/usr/share/perl5/Prophet/CLI/Dispatcher.pm is in libprophet-perl 0.750-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | package Prophet::CLI::Dispatcher;
use Path::Dispatcher::Declarative -base;
use Any::Moose;
extends 'Path::Dispatcher::Declarative', any_moose('Object');
use Prophet::CLI::Dispatcher::Rule::RecordId;
with 'Prophet::CLI::Parameters';
our $cli;
our @PREFIXES = qw(Prophet::CLI::Command);
sub add_command_prefix { unshift @PREFIXES, @_ }
on '' => sub {
my $self = shift;
if ($self->context->has_arg('version')) { run_command("Version")->($self) }
elsif( $self->context->has_arg('help') ){ run_command("Help")->($self) }
else { next_rule }
};
# publish foo@bar.com:www/baz => publish --to foo@bar.com:www/baz
on qr{^(publish|push) (\S+)$} => sub {
my $self = shift;
$self->context->set_arg(to => $2);
run($1, $self);
};
# clone http://fsck.com/~jesse/sd-bugs => clone --from http://fsck.com/~jesse/sd-bugs
on qr{^(clone|pull) (\S+)$} => sub {
my $self = shift;
$self->context->set_arg(from => $2);
run($1, $self);
};
# log range => log --range range
on qr{log\s+([0-9LATEST.~]+)} => sub {
my $self = shift;
$self->context->set_arg(range => $1);
run('log', $self);
};
under settings => sub {
my $self = shift;
on edit => sub {
my $self = shift;
$self->context->set_arg( 'edit' );
run('settings', $self);
};
on show => sub {
my $self = shift;
$self->context->set_arg( 'show' );
run('settings', $self);
};
on set => sub {
my $self = shift;
$self->context->set_arg( 'set' );
run('settings', $self);
};
};
dispatcher->add_rule(
Path::Dispatcher::Rule::Sequence->new(
rules => [
Path::Dispatcher::Rule::Regex->new(
regex => qr/^(update|edit|show|display|delete|del|rm|history)$/,
),
Prophet::CLI::Dispatcher::Rule::RecordId->new,
],
block => sub {
my $match = shift;
my $self = shift;
$self->context->set_id_from_primary_commands;
run($match->pos(1), $self, @_);
},
)
);
on [ [ 'update', 'edit' ] ] => run_command("Update");
on [ [ 'show', 'display' ] ] => run_command("Show");
on [ [ 'delete', 'del', 'rm' ] ] => run_command("Delete");
on history => run_command("History");
on [ ['create', 'new'] ] => run_command("Create");
on [ ['search', 'list', 'ls' ] ] => run_command("Search");
on [ ['aliases', 'alias'] ] => run_command('Aliases');
on version => run_command("Version");
on init => run_command("Init");
on clone => run_command("Clone");
on merge => run_command("Merge");
on mirror => run_command('Mirror');
on pull => run_command("Pull");
on publish => run_command("Publish");
on server => run_command("Server");
on config => run_command("Config");
on settings => run_command("Settings");
on log => run_command("Log");
on shell => run_command("Shell");
on export => run_command('Export');
on info => run_command('Info');
on push => run_command('Push');
on qr/^(alias(?:es)?|config)?\s+(.*)/ => sub {
my ( $self ) = @_;
my $cmd = $1;
my $arg = $2;
my $class = $cmd =~ /^alias/ ? 'Aliases' : 'Config';
# Load command class so we can run
# its arg-parsing sub (the syntax is complex)
my @classes = $self->class_names($class);
for my $class (@classes) {
Prophet::App->try_to_require($class) or next;
my $cmd_obj = $class->new(
context => $self->context,
cli => $self->cli,
);
$cmd_obj->parse_cli_arg($cmd, $arg);
return run( $cmd, $self, @_ );
}
# Something is wrong with the app layout...
die "Could not find '$class' command class";
};
on qr/^_gencomp\s*(.*)/ => sub {
my $self = shift;
my $path = $1;
$path = "" if !defined($path);
print "$_\n" for $self->dispatcher->complete($path);
};
sub run_command {
my $name = shift;
return sub {
my $self = shift;
my %constructor_args = (
cli => $self->cli,
context => $self->context,
commands => $self->context->primary_commands,
type => $self->context->type,
uuid => $self->context->uuid,
);
# undef causes type constraint violations
for my $key (keys %constructor_args) {
delete $constructor_args{$key}
if !defined($constructor_args{$key});
}
my @classes = $self->class_names($name);
for my $class (@classes) {
Prophet::App->try_to_require($class) or next;
$class->new(%constructor_args)->run;
return;
}
die "Invalid command command class suffix '$name'";
};
}
sub class_names {
my $self = shift;
my $command = shift;
return map { $_."::".$command } @PREFIXES;
}
__PACKAGE__->meta->make_immutable;
no Any::Moose;
1;
|