[1980] | 1 | # ------------------------------------------------------------------------------ |
---|
| 2 | # (C) Crown copyright Met Office. All rights reserved. |
---|
| 3 | # For further details please refer to the file COPYRIGHT.txt |
---|
| 4 | # which you should have received as part of this distribution. |
---|
| 5 | # ------------------------------------------------------------------------------ |
---|
| 6 | use strict; |
---|
| 7 | use warnings; |
---|
| 8 | |
---|
| 9 | package Fcm::CLI::Invoker::CfgPrinter; |
---|
| 10 | use base qw{Fcm::CLI::Invoker}; |
---|
| 11 | |
---|
| 12 | use Carp qw{croak}; |
---|
| 13 | use Fcm::Exception; |
---|
| 14 | use Fcm::CfgFile; |
---|
| 15 | use Fcm::Config; |
---|
| 16 | |
---|
| 17 | ################################################################################ |
---|
| 18 | # Invokes the sub-system |
---|
| 19 | sub invoke { |
---|
| 20 | my ($self) = @_; |
---|
| 21 | my ($cfg_file) = $self->get_arguments(); |
---|
| 22 | if (!$cfg_file) { |
---|
| 23 | croak(Fcm::CLI::Exception->new({message => 'no CFGFILE specified'})); |
---|
| 24 | } |
---|
| 25 | my $cfg = Fcm::CfgFile->new(SRC => $cfg_file); |
---|
| 26 | Fcm::Config->instance()->verbose(0); # suppress message printing to STDOUT |
---|
| 27 | my $read = $cfg->read_cfg(); |
---|
| 28 | if (!$read) { |
---|
| 29 | croak(Fcm::Exception->new({message => sprintf( |
---|
| 30 | "% :cannot read", $cfg_file, |
---|
| 31 | )})); |
---|
| 32 | } |
---|
| 33 | $cfg->print_cfg($self->get_options()->{output}); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | 1; |
---|
| 37 | __END__ |
---|
| 38 | |
---|
| 39 | =head1 NAME |
---|
| 40 | |
---|
| 41 | Fcm::CLI::Invoker::CfgPrinter |
---|
| 42 | |
---|
| 43 | =head1 SYNOPSIS |
---|
| 44 | |
---|
| 45 | use Fcm::CLI::Invoker::CfgPrinter; |
---|
| 46 | $invoker = Fcm::CLI::Invoker::CfgPrinter->new({ |
---|
| 47 | command => $command, |
---|
| 48 | options => \%options, |
---|
| 49 | arguments => $arguments, |
---|
| 50 | }); |
---|
| 51 | $invoker->invoke(); |
---|
| 52 | |
---|
| 53 | =head1 DESCRIPTION |
---|
| 54 | |
---|
| 55 | This class extends L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> an inherits all its |
---|
| 56 | methods. An object of this class is used to invoke the pretty printer for FCM |
---|
| 57 | configuration files. |
---|
| 58 | |
---|
| 59 | =head1 METHODS |
---|
| 60 | |
---|
| 61 | See L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> for a list of inherited methods. |
---|
| 62 | |
---|
| 63 | =over 4 |
---|
| 64 | |
---|
| 65 | =item invoke() |
---|
| 66 | |
---|
| 67 | Invokes the pretty printer for a FCM configuration file. |
---|
| 68 | |
---|
| 69 | If the I<output> option is set, output goes to the location specified by this |
---|
| 70 | value. Otherwise, it prints to STDOUT. |
---|
| 71 | |
---|
| 72 | =back |
---|
| 73 | |
---|
| 74 | =head1 DIAGNOSTICS |
---|
| 75 | |
---|
| 76 | =over 4 |
---|
| 77 | |
---|
| 78 | =item L<Fcm::Exception|Fcm::Exception> |
---|
| 79 | |
---|
| 80 | The invoke() method can croak() with this exception if the configuration file |
---|
| 81 | cannot be read. |
---|
| 82 | |
---|
| 83 | =item L<Fcm::CLI::Exception|Fcm::CLI::Exception> |
---|
| 84 | |
---|
| 85 | The invoke() method can croak() with this exception if no configuration file is |
---|
| 86 | specified. |
---|
| 87 | |
---|
| 88 | =back |
---|
| 89 | |
---|
| 90 | =head1 TO DO |
---|
| 91 | |
---|
| 92 | Unit tests. |
---|
| 93 | |
---|
| 94 | =head1 SEE ALSO |
---|
| 95 | |
---|
| 96 | L<Fcm::CfgFile|Fcm::CfgFile>, |
---|
| 97 | L<Fcm::CLI::Exception|Fcm::CLI::Exception>, |
---|
| 98 | L<Fcm::CLI::Invoker|Fcm::CLI::Invoker>, |
---|
| 99 | L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand> |
---|
| 100 | |
---|
| 101 | =head1 COPYRIGHT |
---|
| 102 | |
---|
| 103 | E<169> Crown copyright Met Office. All rights reserved. |
---|
| 104 | |
---|
| 105 | =cut |
---|