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