| 1 | package Serge::Command::help; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use parent Serge::Command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Serge::Pod; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Serge; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Serge::Util::Pager; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub get_commands { | ||||||||||||||||||||||||||||
| 12 | return { | ||||||||||||||||||||||||||||
| 13 | 0 | ▶ | '' => {handler => \&show_default_help}, | ||||||||||||||||||||||||||
|
Subroutine
get_commands: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | help => {handler => \&show_help, info => 'Show help on main application and other commands'}, | ||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub init { | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my ($self, $command) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | $self->SUPER::init($command); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # OS-specific checks | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $self->{browser} = 1 if ($^O eq 'MSWin32'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $console; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | GetOptions( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 'console' => \$console, | ||||||||||||||||||||||||||||
| 30 | ) or die "Failed to parse some command-line parameters."; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | $self->{browser} = undef if $console; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub show_brief_help { | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my ($self, $message) = @_; | ||||||||||||||||||||||||||
|
Subroutine
show_brief_help: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my @commands = sort keys %{$self->{parent}->{commands}}; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | print $message ? $message."\n" : "Serge $Serge::VERSION - Free, Open-Source Solution for Continuous Localization\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | $self->{parent}->show_synopsis; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # determine the max size of commands to render second column | ||||||||||||||||||||||||||||
| 44 | # with their information nicely aligned | ||||||||||||||||||||||||||||
| 45 | 0 | my $max_command_len; | |||||||||||||||||||||||||||
| 46 | 0 | foreach (@commands) { | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | $max_command_len = length($_) if length($_) > $max_command_len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | print "Available commands:\n"; | |||||||||||||||||||||||||||
| 51 | 0 | foreach (@commands) { | |||||||||||||||||||||||||||
| 52 | 0 | my $padding = ' ' x ($max_command_len - length($_)); | |||||||||||||||||||||||||||
| 53 | 0 | my $info = $self->{parent}->{commands}->{$_}->{info}; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | print " $_$padding $info\n" if $_ ne ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub show_default_help { | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my ($self, $command) = @_; | ||||||||||||||||||||||||||
|
Subroutine
show_default_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | $self->show_brief_help; # with no message | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | return 0; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | sub show_help { | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my ($self, $command) = @_; | ||||||||||||||||||||||||||
|
Subroutine
show_help: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | my $help_on_command = shift @ARGV; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($self->{parent}->known_command($help_on_command)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $self->show_help_on_topic($help_on_command eq '' ? 'serge' : "serge-$help_on_command"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||||
| 73 | 0 | $self->show_brief_help("Unknown command: '$help_on_command'"); | |||||||||||||||||||||||||||
| 74 | 0 | return 1; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | return 0; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub show_help_on_topic { | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my ($self, $command) = @_; | ||||||||||||||||||||||||||
|
Subroutine
show_help_on_topic: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | my $pod = Serge::Pod->new(); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (!$self->{browser} || !$self->show_in_browser($pod->get_html_path($command))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{'browser'} && $self->show_in_browser($pod->get_html_path($command))
MC/DC0%0/2
$self->{'browser'} && $self->show_in_browser($pod->get_html_path($command))
$self->{'browser'}
$self->show_in_browser($pod->get_html_path($command))
Truth table0%0/3
A && B
A= $self->{'browser'}B= $self->show_in_browser($pod->get_html_path($command))
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my $podfile = $pod->get_pod_path($command); | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | if (!-f $podfile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | print "Sorry, but there's no help available for '$command' in '$pod->{root}'\n"; | |||||||||||||||||||||||||||
| 90 | 0 | exit(2); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | my $fh = Serge::Util::Pager::init; | |||||||||||||||||||||||||||
| 94 | 0 | $pod->print_as_text($podfile, $fh); | |||||||||||||||||||||||||||
| 95 | 0 | Serge::Util::Pager::close; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub show_in_browser { | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my ($self, $html_file) = @_; | ||||||||||||||||||||||||||
|
Subroutine
show_in_browser: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return undef unless -f $html_file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # Windows | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($^O eq 'MSWin32') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | print "MSWin32: executing `$html_file`\n" if $self->{parent}->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | `$html_file`; # this should open the .html file in the default associated application (typically, browser) | |||||||||||||||||||||||||||
| 108 | 0 | my $exitcode = $? >> 8; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | print "Exit code: $exitcode\n" if $self->{parent}->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | return $exitcode == 0; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | return undef; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | 1; | |||||||||||||||||||||||||||