New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
ConfigSystem.pm in branches/UKMO/smagorinsky_diagnostics/NEMOGCM/EXTERNAL/fcm/lib/Fcm/CLI/Invoker – NEMO

source: branches/UKMO/smagorinsky_diagnostics/NEMOGCM/EXTERNAL/fcm/lib/Fcm/CLI/Invoker/ConfigSystem.pm @ 5699

Last change on this file since 5699 was 5699, checked in by davestorkey, 9 years ago

Remove SVN keyword updating from UKMO/smagorinsky_diagnostics branch.

File size: 3.3 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::ConfigSystem;
10use base qw{Fcm::CLI::Invoker};
11
12use Cwd qw{cwd};
13use Fcm::CLI::Exception;
14use Fcm::Config;
15use Fcm::Util::ClassLoader;
16
17################################################################################
18# Returns a hash map to convert CLI options to system invoke options.
19sub get_cli2invoke_key_map {
20    my ($self) = @_;
21    return (
22          wantarray() ? %{$self->{cli2invoke_key_map}}
23        :               $self->{cli2invoke_key_map}
24    );
25}
26
27################################################################################
28# Returns the Fcm::ConfigSystem class for invoking the sub-system.
29sub get_impl_class {
30    my ($self) = @_;
31    return $self->{impl_class};
32}
33
34################################################################################
35# Invokes the sub-system
36sub invoke {
37    my ($self) = @_;
38    my $options_ref = $self->get_options();
39    if (exists($options_ref->{verbose})) {
40        Fcm::Config->instance()->verbose($options_ref->{verbose});
41    }
42
43    Fcm::Util::ClassLoader::load($self->get_impl_class());
44    my $system = $self->get_impl_class()->new();
45    my ($cfg_file) = $self->get_arguments();
46    $system->cfg()->src($cfg_file ? $cfg_file : cwd());
47
48    my %map = $self->get_cli2invoke_key_map();
49    my %invoke_args = map {($map{$_}, $options_ref->{$_})} keys(%map);
50    $system->invoke(%invoke_args);
51}
52
531;
54__END__
55
56=head1 NAME
57
58Fcm::CLI::Invoke::ConfigSystem
59
60=head1 SYNOPSIS
61
62    use Fcm::CLI::Invoker::ConfigSystem;
63    $invoker = Fcm::CLI::Invoker::ConfigSystem->new({
64        command            => $command,
65        options            => \%options,
66        arguments          => $arguments,
67        impl_class         => $class_name,
68        cli2invoke_key_map => {
69            option => 'OPTION',
70            # ... more keys
71        },
72    });
73    $invoker->invoke();
74
75=head1 DESCRIPTION
76
77This class extends L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> and inherits all its
78methods. An object of this class is used to invoke a
79L<Fcm::ConfigSystem|Fcm::ConfigSystem>, e.g. extract and build.
80
81=head1 METHODS
82
83See L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> for a list of inherited methods.
84
85=over 4
86
87=item get_cli2invoke_key_map()
88
89Returns a hash containing a mapping table from the names of the relevant command
90line options to the names to be given to the invoke() method of the implementing
91L<Fcm::ConfigSystem|Fcm::ConfigSystem> object.
92
93=item get_impl_class()
94
95Returns the actual class that implements L<Fcm::ConfigSystem|Fcm::ConfigSystem>.
96An object of this implementation will be created and used by invoke().
97
98=item invoke()
99
100Invokes the L<Fcm::ConfigSystem|Fcm::ConfigSystem> sub-system. If a
101configuration file is not specified in the argument, it uses the current working
102directory.
103
104=back
105
106=head1 SEE ALSO
107
108L<Fcm::ConfigSystem|Fcm::ConfigSystem>,
109L<Fcm::CLI::Exception|Fcm::CLI::Exception>,
110L<Fcm::CLI::Invoker|Fcm::CLI::Invoker>,
111L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand>
112
113=head1 COPYRIGHT
114
115E<169> Crown copyright Met Office. All rights reserved.
116
117=cut
Note: See TracBrowser for help on using the repository browser.