source: XMLIO_V2/tools/FCM/lib/Fcm/CLI/Invoker/CfgPrinter.pm @ 81

Last change on this file since 81 was 81, checked in by ymipsl, 14 years ago

ajout FCM 1.5

File size: 2.5 KB
Line 
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# ------------------------------------------------------------------------------
6use strict;
7use warnings;
8
9package Fcm::CLI::Invoker::CfgPrinter;
10use base qw{Fcm::CLI::Invoker};
11
12use Carp qw{croak};
13use Fcm::Exception;
14use Fcm::CfgFile;
15use Fcm::Config;
16
17################################################################################
18# Invokes the sub-system
19sub 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
361;
37__END__
38
39=head1 NAME
40
41Fcm::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
55This class extends L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> an inherits all its
56methods. An object of this class is used to invoke the pretty printer for FCM
57configuration files.
58
59=head1 METHODS
60
61See L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> for a list of inherited methods.
62
63=over 4
64
65=item invoke()
66
67Invokes the pretty printer for a FCM configuration file.
68
69If the I<output> option is set, output goes to the location specified by this
70value.  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
80The invoke() method can croak() with this exception if the configuration file
81cannot be read.
82
83=item L<Fcm::CLI::Exception|Fcm::CLI::Exception>
84
85The invoke() method can croak() with this exception if no configuration file is
86specified.
87
88=back
89
90=head1 TO DO
91
92Unit tests.
93
94=head1 SEE ALSO
95
96L<Fcm::CfgFile|Fcm::CfgFile>,
97L<Fcm::CLI::Exception|Fcm::CLI::Exception>,
98L<Fcm::CLI::Invoker|Fcm::CLI::Invoker>,
99L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand>
100
101=head1 COPYRIGHT
102
103E<169> Crown copyright Met Office. All rights reserved.
104
105=cut
Note: See TracBrowser for help on using the repository browser.