File Coverage

blib/lib/App/Sqitch/Command/help.pm
Criterion Covered Total %
statement 32 32 100.0
branch 7 8 87.5
condition n/a
subroutine 12 12 100.0
pod 2 2 100.0
total 53 54 98.1


line stmt bran cond sub pod time code
1             package App::Sqitch::Command::help;
2              
3 5     5   2849 use 5.010;
  5         24  
4 5     5   38 use strict;
  5         18  
  5         170  
5 5     5   33 use warnings;
  5         13  
  5         175  
6 5     5   27 use utf8;
  5         18  
  5         46  
7 5     5   230 use Locale::TextDomain qw(App-Sqitch);
  5         16  
  5         69  
8 5     5   1640 use App::Sqitch::X qw(hurl);
  5         17  
  5         65  
9 5     5   2033 use Types::Standard qw(Bool);
  5         15  
  5         103  
10 5     5   4968 use Pod::Find;
  5         12  
  5         257  
11 5     5   29 use Moo;
  5         35  
  5         47  
12             extends 'App::Sqitch::Command';
13              
14             our $VERSION = 'v1.4.0'; # VERSION
15              
16             has guide => (
17             is => 'ro',
18             isa => Bool,
19             default => 0,
20             );
21              
22             sub options {
23             # XXX Add --all at some point, to output a list of all possible commands.
24 8     8 1 6495 return qw(
25             guide|g
26             );
27             }
28              
29             sub execute {
30 5     5   7850 my ( $self, $command ) = @_;
31 5 100       48 $self->find_and_show('sqitch' . (
    50          
    100          
32             $command ? ($command =~ /^changes|tutorial/ ? '' : '-') . $command
33             : $self->guide ? 'guides'
34             : 'commands'
35             ));
36             }
37              
38             sub find_and_show {
39 6     6 1 17 my ( $self, $look_for ) = (shift, shift);
40              
41 6 100       4093 my $pod = Pod::Find::pod_where({
42             '-inc' => 1,
43             '-script' => 1
44             }, $look_for ) or hurl {
45             ident => 'help',
46             message => __x('No manual entry for {command}', command => $look_for),
47             exitval => 1,
48             };
49              
50 5         52 $self->_pod2usage(
51             '-input' => $pod,
52             '-verbose' => 2,
53             '-exitval' => 0,
54             @_,
55             );
56             }
57              
58             1;
59              
60             __END__
61              
62             =head1 Name
63              
64             App::Sqitch::Command::help - Display help information about Sqitch
65              
66             =head1 Synopsis
67              
68             my $cmd = App::Sqitch::Command::help->new(%params);
69             $cmd->execute;
70              
71             =head1 Description
72              
73             If you want to know how to use the C<help> command, you probably want to be
74             reading C<sqitch-help>. But if you really want to know how the C<help> command
75             works, read on.
76              
77             =head1 Interface
78              
79             =head2 Attributes
80              
81             =head3 C<guide>
82              
83             Boolean indicating whether to list the guides.
84              
85             =head2 Instance Methods
86              
87             =head3 C<execute>
88              
89             $help->execute($command);
90              
91             Executes the help command. If a command is passed, the help for that command will
92             be shown. If it cannot be found, Sqitch will throw an error and exit. If no
93             command is specified, the L<Sqitch core documentation|sqitch> will be shown.
94              
95             =head3 C<find_and_show>
96              
97             $help->find_and_show($file, %options);
98              
99             Does the work of finding the pod file C<$file> and passing it on to
100             L<Pod::Usage>, along with any additional options for Pod::Usage's constructor.
101              
102             =head1 See Also
103              
104             =over
105              
106             =item L<sqitch-help>
107              
108             Documentation for the C<help> command to the Sqitch command-line client.
109              
110             =item L<sqitch>
111              
112             The Sqitch command-line client.
113              
114             =back
115              
116             =head1 Author
117              
118             David E. Wheeler <david@justatheory.com>
119              
120             =head1 License
121              
122             Copyright (c) 2012-2023 iovation Inc., David E. Wheeler
123              
124             Permission is hereby granted, free of charge, to any person obtaining a copy
125             of this software and associated documentation files (the "Software"), to deal
126             in the Software without restriction, including without limitation the rights
127             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
128             copies of the Software, and to permit persons to whom the Software is
129             furnished to do so, subject to the following conditions:
130              
131             The above copyright notice and this permission notice shall be included in all
132             copies or substantial portions of the Software.
133              
134             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
135             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
136             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
137             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
138             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
139             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
140             SOFTWARE.
141              
142             =cut