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.
Config.pm in branches/UKMO/r6232_tracer_advection/NEMOGCM/EXTERNAL/fcm/lib/Fcm/CLI – NEMO

source: branches/UKMO/r6232_tracer_advection/NEMOGCM/EXTERNAL/fcm/lib/Fcm/CLI/Config.pm @ 9295

Last change on this file since 9295 was 9295, checked in by jcastill, 6 years ago

Remove svn keywords

File size: 3.8 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::Config;
10
11use Fcm::CLI::Config::Default;
12use List::Util qw{first};
13use Scalar::Util qw{blessed};
14
15my $INSTANCE;
16
17################################################################################
18# Class method: returns an instance of this class
19sub instance {
20    my ($class, $args_ref) = @_;
21    if ($args_ref || !$INSTANCE) {
22        $INSTANCE = bless({
23            core_subcommands => [@Fcm::CLI::Config::Default::CORE_SUBCOMMANDS],
24            vc_subcommands   => [@Fcm::CLI::Config::Default::VC_SUBCOMMANDS],
25            (defined($args_ref) ? %{$args_ref} : ()), 
26        }, $class);
27    }
28    return $INSTANCE;
29}
30
31################################################################################
32# Returns a subcommand matching $key
33sub get_subcommand_of {
34    my ($self, $key) = @_;
35    if (blessed($key) && $key->isa('Fcm::CLI::Subcommand')) {
36        return first {"$_" eq "$key"} ($self->get_subcommands());
37    }
38    else {
39        return first {$_->has_a_name($key)} ($self->get_subcommands());
40    }
41}
42
43################################################################################
44# Returns the subcommands
45sub get_subcommands {
46    my ($self) = @_;
47    my @return = ($self->get_core_subcommands(), $self->get_vc_subcommands());
48    return (wantarray() ? @return : \@return);
49}
50
51################################################################################
52# Returns the core subcommands
53sub get_core_subcommands {
54    my ($self) = @_;
55    return (
56        wantarray() ? @{$self->{core_subcommands}} : $self->{core_subcommands}
57    );
58}
59
60################################################################################
61# Returns the subcommands that are relevant only with a VC system
62sub get_vc_subcommands {
63    my ($self) = @_;
64    return (wantarray() ? @{$self->{vc_subcommands}} : $self->{vc_subcommands});
65}
66
671;
68__END__
69
70=head1 NAME
71
72Fcm::CLI::Config
73
74=head1 SYNOPSIS
75
76    use Fcm::CLI::Config;
77    $cli_config = Fcm::CLI::Config->instance();
78    $subcommand = $cli_config->get_subcommand_of($key);
79    @subcommands = $cli_config->get_subcommands();
80    @core_subcommands = $cli_config->get_core_subcommands();
81    @vc_subcommands = $cli_config->get_vc_subcommands();
82
83=head1 DESCRIPTION
84
85This class provides the configuration of the FCM command line interface.
86
87=head1 METHODS
88
89=over 4
90
91=item instance($arg_ref)
92
93Returns an instance of this class.
94
95Creates the instance on first call, or replaces it with a new one if $args_ref
96is defined in subsequent call. $args_ref should be a reference to a hash. The
97hash can contain I<core_subcommands> and I<vc_subcommands>. Each of these
98settings should point to an array reference containing L<Fcm::CLI::Subcommand>
99objects. If the setting is unspecified, it uses the default from
100L<Fcm::CLI::Config::Default|Fcm::CLI::Config::Default>.
101
102=item get_subcommand_of($key)
103
104Returns a L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand> object matching the
105search $key. Returns undef if there is no match.
106
107=item get_subcommands()
108
109Short-hand for:
110    ($self->get_core_subcommands(), $self->get_vc_subcommands())
111
112=item get_core_subcommands()
113
114Returns the core subcommands.
115
116=item get_vc_subcommands()
117
118Returns the subcommands that are relevant only in the presence of a VC system.
119
120=back
121
122=head1 SEE ALSO
123
124L<Fcm::CLI::Config::Default|Fcm::CLI::Config::Default>,
125L<Fcm::CLI::Invoker|Fcm::CLI::Invoker>,
126L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand>,
127L<Fcm::CLI::Option|Fcm::CLI::Option>
128
129=head1 COPYRIGHT
130
131E<169> Crown copyright Met Office. All rights reserved.
132
133=cut
Note: See TracBrowser for help on using the repository browser.