| 1 | # ABSTRACT: fetch feeds and constrain with rules, all from a config file | ||
| 2 | |||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | package App::Rssfilter::Cmd::runfromconfig; | ||
| 8 | $App::Rssfilter::Cmd::runfromconfig::VERSION = '0.08'; # TRIAL | ||
| 9 | use App::Rssfilter::Cmd -command; | ||
| 10 | use App::Rssfilter; | ||
| 11 | use Method::Signatures; | ||
| 12 | use Cwd; | ||
| 13 | use Path::Class qw<>; | ||
| 14 | use Log::Any::Adapter; | ||
| 15 | |||
| 16 | method usage_desc( $app ) { | ||
| 17 | return $app->arg0 . ' %o'; | ||
| 18 | } | ||
| 19 | |||
| 20 | |||
| 21 | method opt_spec( $app ) { | ||
| 22 | return ( | ||
| 23 | [ 'config-file|f:s', 'config file for App::Rssfilter (searches for RssFilter.yaml if not set)', ], | ||
| 24 | [ 'log|v', 'turn logging on' ], | ||
| 25 | ); | ||
| 26 | } | ||
| 27 | |||
| 28 | method validate_args( $opt, $args ) { } | ||
| 29 | |||
| 30 | method find_config( :$file = 'Rssfilter.yaml', :$dir = cwd() ) { | ||
| 31 | $dir = Path::Class::dir->new( $dir )->absolute; | ||
| 32 | for( reverse $dir->dir_list ) { | ||
| 33 | my $filename = $dir->file( $file ); | ||
| 34 | return $filename if -r $filename; | ||
| 35 | last; # directory search later | ||
| 36 | $dir = $dir->parent; | ||
| 37 | } | ||
| 38 | return $file; | ||
| 39 | } | ||
| 40 | |||
| 41 | method execute( $opt, $args ) { | ||
| 42 | my $yaml_config = Path::Class::file( $opt->config_file // $self->find_config ); | ||
| 43 | Log::Any::Adapter->set( 'Stdout' ) if $opt->log; | ||
| 44 | App::Rssfilter->from_yaml( scalar $yaml_config->slurp )->update(); | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; | ||
| 48 | |||
| 49 | __END__ |