source: branches/2015/dev_r5021_UKMO1_CICE_coupling/NEMOGCM/EXTERNAL/fcm/lib/Fcm/CLI/Invoker/Browser.pm @ 5445

Last change on this file since 5445 was 5445, checked in by davestorkey, 5 years ago

Clear SVN keywords from 2015/dev_r5021_UKMO1_CICE_coupling branch.

File size: 3.0 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::Browser;
10use base qw{Fcm::CLI::Invoker};
11
12use Carp qw{croak};
13use Fcm::CLI::Exception;
14use Fcm::Config;
15use Fcm::Keyword;
16use Fcm::Util qw{expand_tilde get_url_of_wc is_wc run_command};
17
18################################################################################
19# Invokes the sub-system
20sub invoke {
21    my ($self) = @_;
22    my $config = Fcm::Config->instance();
23    my $browser
24        = $self->get_options()->{browser} ? $self->get_options()->{browser}
25        :                                   $config->setting(qw/WEB_BROWSER/)
26        ;
27    my ($target) = $self->get_arguments();
28    if (!$target) {
29        if (is_wc()) {
30            $target = q{.};
31        }
32        else {
33            croak(Fcm::CLI::Exception->new({
34                message => 'no TARGET specified and . not a working copy',
35            }));
36        }
37    }
38    $target = expand_tilde($target);
39    if (-e $target) {
40        $target = get_url_of_wc($target);
41    }
42
43    my $browser_url = Fcm::Keyword::get_browser_url($target);
44    my @command = (split(qr{\s+}xms, $browser), $browser_url);
45    run_command(\@command, METHOD => 'exec', PRINT => 1);
46}
47
481;
49__END__
50
51=head1 NAME
52
53Fcm::CLI::Invoker::Browser
54
55=head1 SYNOPSIS
56
57    use Fcm::CLI::Invoker::Browser;
58    $invoker = Fcm::CLI::Invoker::Browser->new({
59        command   => $command,
60        options   => \%options,
61        arguments => $arguments,
62    });
63    $invoker->invoke();
64
65=head1 DESCRIPTION
66
67This class extends L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> an inherits all its
68methods. An object of this class is used to invoke a web browser of a VC
69location.
70
71=head1 METHODS
72
73See L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> for a list of inherited methods.
74
75=over 4
76
77=item invoke()
78
79Invokes a web browser for a VC target, if it can be mapped to a browser URL. If
80a target is not specified in arguments, it uses the current working directory
81as the target.
82
83If the browser option is set, it is used as the browser command. Otherwise, the
84default browser is used.
85
86=back
87
88=head1 DIAGNOSTICS
89
90=over 4
91
92=item L<Fcm::CLI::Exception|Fcm::CLI::Exception>
93
94The invoke() method can croak() with this exception if no target is specified
95and a target cannot be deduced from the current working directory.
96
97=item L<Fcm::Keyword::Exception|Fcm::Keyword::Exception>
98
99The invoke() method can croak() with this exception if the target cannot be
100mapped to a browser URL.
101
102=back
103
104=head1 TO DO
105
106Unit tests.
107
108=head1 SEE ALSO
109
110L<Fcm::CLI::Exception|Fcm::CLI::Exception>,
111L<Fcm::CLI::Invoker|Fcm::CLI::Invoker>,
112L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand>,
113L<Fcm::Keyword|Fcm::Keyword>
114
115=head1 COPYRIGHT
116
117E<169> Crown copyright Met Office. All rights reserved.
118
119=cut
Note: See TracBrowser for help on using the repository browser.