| 1 | package App::CSAF::ROLIE; | ||
| 2 | |||
| 3 | use 5.010001; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use utf8; | ||
| 7 | |||
| 8 | use Carp; | ||
| 9 | use File::Spec::Functions qw(catfile); | ||
| 10 | use Getopt::Long qw( GetOptionsFromArray :config gnu_compat ); | ||
| 11 | use Pod::Usage; | ||
| 12 | use YAML::XS 'LoadFile'; | ||
| 13 | |||
| 14 | use CSAF; | ||
| 15 | use CSAF::Util::App qw(cli_error cli_version); | ||
| 16 | use CSAF::ROLIE::Feed; | ||
| 17 | |||
| 18 | sub run { | ||
| 19 | |||
| 20 | my ($class, @args) = @_; | ||
| 21 | |||
| 22 | my %options = (); | ||
| 23 | |||
| 24 | delete $ENV{CSAF_DEBUG}; | ||
| 25 | |||
| 26 | GetOptionsFromArray( | ||
| 27 | \@args, \%options, qw( | ||
| 28 | csaf|d=s | ||
| 29 | output=s | ||
| 30 | |||
| 31 | tlp-label=s | ||
| 32 | feed-title=s | ||
| 33 | feed-id=s | ||
| 34 | base-url=s | ||
| 35 | |||
| 36 | test | ||
| 37 | stdout | ||
| 38 | config|c=s | ||
| 39 | |||
| 40 | help|h | ||
| 41 | man | ||
| 42 | version|v | ||
| 43 | verbose | ||
| 44 | ) | ||
| 45 | ) or pod2usage(-verbose => 0); | ||
| 46 | |||
| 47 | pod2usage(-exitstatus => 0, -verbose => 2) if defined $options{man}; | ||
| 48 | pod2usage(-exitstatus => 0, -verbose => 0) if defined $options{help}; | ||
| 49 | |||
| 50 | return cli_version if defined $options{version}; | ||
| 51 | |||
| 52 | if (defined $options{config}) { | ||
| 53 | unless (-e $options{config}) { | ||
| 54 | cli_error("Config file not found"); | ||
| 55 | return 255; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | my $rolie = CSAF::ROLIE::Feed->new(); | ||
| 60 | |||
| 61 | $rolie->options->config_file($options{'config'}) if defined $options{'config'}; | ||
| 62 | |||
| 63 | $rolie->options->csaf_directory($options{'csaf'}) if defined $options{'csaf'}; | ||
| 64 | $rolie->options->tlp_label($options{'tlp-label'}) if defined $options{'tlp-label'}; | ||
| 65 | $rolie->options->base_url($options{'base-url'}) if defined $options{'base-url'}; | ||
| 66 | $rolie->options->feed_id($options{'feed-id'}) if defined $options{'feed-id'}; | ||
| 67 | $rolie->options->feed_title($options{'feed-title'}) if defined $options{'feed-title'}; | ||
| 68 | |||
| 69 | unless ($rolie->options->csaf_directory) { | ||
| 70 | cli_error("Specify CSAF input directory"); | ||
| 71 | return 255; | ||
| 72 | } | ||
| 73 | |||
| 74 | unless (-e -d $rolie->options->csaf_directory) { | ||
| 75 | cli_error("CSAF input directory not found"); | ||
| 76 | return 255; | ||
| 77 | } | ||
| 78 | |||
| 79 | $options{output} = catfile($rolie->options->csaf_directory, $rolie->options->feed_filename) | ||
| 80 | unless defined $options{output}; | ||
| 81 | |||
| 82 | say STDERR 'CSAF directory : ' . $rolie->options->csaf_directory; | ||
| 83 | say STDERR 'TLP label : ' . $rolie->options->tlp_label(); | ||
| 84 | say STDERR 'Base URL : ' . $rolie->options->base_url(); | ||
| 85 | say STDERR 'Feed ID : ' . $rolie->options->feed_id(); | ||
| 86 | say STDERR 'Feed title : ' . $rolie->options->feed_title(); | ||
| 87 | say STDERR 'Feed filename : ' . $rolie->options->feed_filename(); | ||
| 88 | say STDERR 'Output file : ' . $options{output}; | ||
| 89 | |||
| 90 | return 0 if ($options{test}); | ||
| 91 | |||
| 92 | eval { $rolie->from_csaf_directory($rolie->options->csaf_directory) }; | ||
| 93 | |||
| 94 | return cli_error($@) if $@; | ||
| 95 | |||
| 96 | if (defined $options{stdout}) { | ||
| 97 | say $rolie->render; | ||
| 98 | return 0; | ||
| 99 | } | ||
| 100 | |||
| 101 | $rolie->write($options{output}); | ||
| 102 | say STDERR "ROLIE feed saved in $options{output}"; | ||
| 103 | return 0; | ||
| 104 | |||
| 105 | } | ||
| 106 | |||
| 107 | 1; | ||
| 108 | |||
| 109 | __END__ |