forked from paultcochrane/app-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Commands.pm
45 lines (30 loc) · 912 Bytes
/
Commands.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package App::CLI::Command::Commands;
use strict;
use warnings;
use base qw/App::CLI::Command/;
=head1 NAME
App::CLI::Command::Commands - Print a list of commands for your app
=head1 SYNOPSIS
package MyApp;
use base qw(App::CLI App::CLI::Command);
# Make your app get a list of commands
use constant alias => (
commands => 'App::CLI::Command::Commands',
);
1;
=head1 DESCRIPTION
Print a list of commands registered for your application;
=cut
sub run {
my ($self) = shift;
my ($longest) = sort {length($b) cmp length($a)} $self->app->commands;
$longest = length $longest;
foreach ($self->app->commands) {
my $cmd = $self->app->get_cmd($_);
my @components = split /::/, ref $cmd;
my $name = lc pop @components;
printf " %${longest}s: %s\n", $name, lc($cmd->abstract) || '[ undocumented ]';
}
print "\n";
}
1;