summaryrefslogtreecommitdiff
path: root/lib/Net/HTTP
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Net/HTTP')
-rw-r--r--lib/Net/HTTP/Console/Dispatcher/Help.pm57
1 files changed, 49 insertions, 8 deletions
diff --git a/lib/Net/HTTP/Console/Dispatcher/Help.pm b/lib/Net/HTTP/Console/Dispatcher/Help.pm
index d38b186..7055b2b 100644
--- a/lib/Net/HTTP/Console/Dispatcher/Help.pm
+++ b/lib/Net/HTTP/Console/Dispatcher/Help.pm
@@ -5,16 +5,21 @@ with qw/Net::HTTP::Console::Dispatcher/;
sub dispatch {
my ($self, $input) = @_;
- $input =~ /^help\s(.*)?/;
- my $cmd = $1;
- if ($cmd) {
- }else{
- print <<EOF
-help command - help about a command
-help request - help about request
-EOF
+ (my $cmd, my $cmd_name) = $input =~ /^help\s(\w+)?\s?(\w+)?/;
+
+ if ($cmd) {
+ if ($cmd eq 'command' && $cmd_name) {
+ $self->_get_help_for_command($cmd_name);
+ }
+ elsif ($cmd eq 'command') {
+ $self->_list_commands();
+ }
+ }
+ else {
+ $self->_display_help();
}
+ 1;
}
sub pattern {
@@ -22,4 +27,40 @@ sub pattern {
$input =~ /^help/ ? return $input : return 0;
}
+sub _display_help {
+ print <<EOF
+help command - help about a command
+help request - help on how to write request
+EOF
+}
+
+sub _list_commands {
+ my $self = shift;
+ my @methods =
+ $self->application->api_object->meta->get_all_net_api_methods();
+
+ if (!@methods) {
+ print "no method available\n";
+ return;
+ }
+
+ print "available commands:\n";
+ map { print "- " . $_ . "\n" } @methods;
+}
+
+sub _get_help_for_command {
+ my ($self, $cmd_name) = @_;
+
+ my $method =
+ $self->application->api_object->meta->find_net_api_method_by_name(
+ $cmd_name);
+
+ if (!$method) {
+ print "unknown method " . $cmd_name . "\n";
+ return;
+ }
+
+ print $method->documentation;
+}
+
1;