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

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

Remove svn keywords

File size: 3.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::KeywordPrinter;
10use base qw{Fcm::CLI::Invoker};
11
12use Carp qw{croak};
13use Fcm::CLI::Exception;
14use Fcm::Keyword;
15use Fcm::Keyword::Formatter::Entries;
16use Fcm::Keyword::Formatter::Entry::Location;
17use Fcm::Keyword::Exception;
18use Fcm::Util qw{get_url_of_wc};
19
20################################################################################
21# Invokes the sub-system
22sub invoke {
23    my ($self) = @_;
24    my @targets = $self->get_arguments();
25    if (@targets) {
26        for my $target (@targets) {
27            my $entry_list = Fcm::Keyword::get_location_entries_for($target);
28            my $loc = $target;
29            if (-e $target) {
30                $loc = get_url_of_wc($target);
31                if (!$loc) {
32                    croak(Fcm::Keyword::Exception->new({message => sprintf(
33                        "%s: unrecognised version control resource", $target,
34                    )}));
35                }
36            }
37            my @entry_list = Fcm::Keyword::get_location_entries_for($loc);
38            if (!@entry_list) {
39                croak(Fcm::Keyword::Exception->new({message => sprintf(
40                    "%s: no FCM location keyword found for this target", $target,
41                )}));
42            }
43            my $formatter = Fcm::Keyword::Formatter::Entry::Location->new();
44            for my $entry (
45                sort {$a->get_key() cmp $b->get_key()}
46                grep {!$_->is_implied()}
47                @entry_list
48            ) {
49                print($formatter->format($entry), "\n");
50            }
51        }
52    }
53    else {
54        my $formatter = Fcm::Keyword::Formatter::Entries->new();
55        print($formatter->format(Fcm::Keyword::get_entries()));
56    }
57}
58
591;
60__END__
61
62=head1 NAME
63
64Fcm::CLI::Invoker::KeywordPrinter
65
66=head1 SYNOPSIS
67
68    use Fcm::CLI::Invoker::KeywordPrinter;
69    $invoker = Fcm::CLI::Invoker::KeywordPrinter->new({
70        command   => $command,
71        options   => \%options,
72        arguments => $arguments,
73    });
74    $invoker->invoke();
75
76=head1 DESCRIPTION
77
78This class extends L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> an inherits all its
79methods. An object of this class is used to invoke the location keyword printer.
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 invoke()
88
89Invokes the location keyword printer. If a namespace is specified in the
90argument, prints revision keywords and browser mapping templates for the
91specified namespace. If a namespace is not specified, prints all registered
92location keywords.
93
94=back
95
96=head1 DIAGNOSTICS
97
98=over 4
99
100=item L<Fcm::Keyword::Exception|Fcm::Keyword::Exception>
101
102The invoke() method can croak() with this exception if there is no matching
103namespace matching that of the specified.
104
105=back
106
107=head1 TO DO
108
109Unit tests.
110
111=head1 SEE ALSO
112
113L<Fcm::CLI::Exception|Fcm::CLI::Exception>,
114L<Fcm::CLI::Invoker|Fcm::CLI::Invoker>,
115L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand>,
116L<Fcm::Keyword|Fcm::Keyword>,
117L<Fcm::Keyword::Formatter::Entries|Fcm::Keyword::Formatter::Entries>,
118L<Fcm::Keyword::Formatter::Entry::Location|Fcm::Keyword::Formatter::Entry::Location>
119
120=head1 COPYRIGHT
121
122E<169> Crown copyright Met Office. All rights reserved.
123
124=cut
Note: See TracBrowser for help on using the repository browser.