File Coverage

blib/lib/App/VTide/Command/Help.pm
Criterion Covered Total %
statement 18 64 28.1
branch 0 16 0.0
condition 0 2 0.0
subroutine 6 10 60.0
pod 3 4 75.0
total 27 96 28.1


line stmt bran cond sub pod time code
1             package App::VTide::Command::Help;
2              
3             # Created on: 2016-02-05 10:11:54
4             # Create by: Ivan Wills
5             # $Id$
6             # $Revision$, $HeadURL$, $Date$
7             # $Revision$, $Source$, $Date$
8              
9 1     1   988 use Moo;
  1         3  
  1         5  
10 1     1   2386 use warnings;
  1         3  
  1         25  
11 1     1   5 use version;
  1         1  
  1         5  
12 1     1   55 use Carp;
  1         2  
  1         47  
13 1     1   5 use English qw/ -no_match_vars /;
  1         3  
  1         4  
14 1     1   973 use Pod::Usage;
  1         48974  
  1         777  
15              
16             extends 'App::VTide::Command::Run';
17              
18             our $VERSION = version->new('1.0.2');
19             our $NAME = 'help';
20             our $OPTIONS = [ 'test|T!', 'verbose|v+', ];
21 0     0 1   sub details_sub { return ( $NAME, $OPTIONS ) }
22              
23             sub run {
24 0     0 1   my ($self) = @_;
25 0           my $command = shift @ARGV;
26              
27 0           my $sub = $self->vtide->_sub_commands;
28              
29 0 0         if ($command) {
30 0           my $module = $self->cmd2module($command);
31 0 0         if ( !$INC{$module} ) {
32 0           require "$module"; ## no critic
33             }
34              
35             pod2usage(
36             -verbose => 1,
37 0           -input => $INC{$module},
38             );
39             }
40             else {
41 0           my $max = 0;
42 0           for my $cmd ( keys %$sub ) {
43 0           my $file = $self->cmd2module($cmd);
44              
45 0 0         if ( !$INC{$file} ) {
46 0           require "$file"; ## no critic
47             }
48 0 0         if ( length $cmd > $max ) {
49 0           $max = length $cmd;
50             }
51 0           my $module = $file;
52 0           $module =~ s{/}{::}g;
53 0           $module =~ s{[.]pm$}{};
54 0           my ( $name, $options, $local ) = $module->details_sub();
55 0   0       $sub->{$cmd} = {
56             module => $file,
57             local => $local || 0,
58             };
59             }
60              
61 0           my $last = -1;
62              
63             # show the list of commands and their descriptions
64 0           for my $cmd (
65 0 0         sort { $sub->{$a}{local} <=> $sub->{$b}{local} || $a cmp $b }
66             keys %$sub
67             ) {
68 0           require Tie::Handle::Scalar;
69 0           my $out = '';
70 0           tie *FH, 'Tie::Handle::Scalar', \$out;
71              
72             pod2usage(
73             -verbose => 99,
74             -input => $INC{ $sub->{$cmd}{module} },
75 0           -exitval => 'NOEXIT',
76             -output => \*FH,
77             -sections => [qw/ NAME /],
78             );
79              
80 0 0         if ( $sub->{$cmd}{local} ne $last ) {
81 0 0         print +( $sub->{$cmd}{local} ? "\nLocal" : 'Global' ), "\n";
82 0           $last = $sub->{$cmd}{local};
83             }
84              
85 0           $out =~ s/\s\s+/ /gxms;
86 0           $out
87 0           =~ s/Name:\s+App::VTide::Command::\w+/sprintf "%-${max}s", $cmd/exms;
88 0           print "$out\n";
89             }
90             }
91              
92 0           return;
93             }
94              
95             sub cmd2module {
96 0     0 0   my ( $self, $cmd ) = @_;
97              
98 0           my $title = join '', map { ucfirst $_ } split /-/, $cmd;
  0            
99              
100 0           return 'App/VTide/Command/' . $title . '.pm';
101             }
102              
103             sub auto_complete {
104 0     0 1   my ($self) = @_;
105              
106 0           my $env = $self->options->files->[-1];
107 0           my $sub = $self->vtide->_sub_commands;
108              
109 0 0         print join ' ', grep { $env ne 'help' ? /^$env/xms : 1 } sort keys %$sub;
  0            
110              
111 0           return;
112             }
113              
114             1;
115              
116             __END__
117              
118             =head1 NAME
119              
120             App::VTide::Command::Help - Show help for vtide commands
121              
122             =head1 VERSION
123              
124             This documentation refers to App::VTide::Command::Help version 1.0.2
125              
126             =head1 SYNOPSIS
127              
128             vtide help
129             vtide help command
130              
131             OPTIONS:
132             --help Show this help
133             --man Show full documentation
134              
135             =head1 DESCRIPTION
136              
137             =head1 SUBROUTINES/METHODS
138              
139             =head2 C<run ()>
140              
141             Displays help for all available commands and individual commands
142              
143             =head2 C<auto_complete ()>
144              
145             Auto completes sub-commands that can have help shown
146              
147             =head2 C<details_sub ()>
148              
149             Returns the commands details
150              
151             =head1 DIAGNOSTICS
152              
153             =head1 CONFIGURATION AND ENVIRONMENT
154              
155             =head1 DEPENDENCIES
156              
157             =head1 INCOMPATIBILITIES
158              
159             =head1 BUGS AND LIMITATIONS
160              
161             There are no known bugs in this module.
162              
163             Please report problems to Ivan Wills (ivan.wills@gmail.com).
164              
165             Patches are welcome.
166              
167             =head1 AUTHOR
168              
169             Ivan Wills - (ivan.wills@gmail.com)
170              
171             =head1 LICENSE AND COPYRIGHT
172              
173             Copyright (c) 2016 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
174             All rights reserved.
175              
176             This module is free software; you can redistribute it and/or modify it under
177             the same terms as Perl itself. See L<perlartistic>. This program is
178             distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
179             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
180             PARTICULAR PURPOSE.
181              
182             =cut