diff options
author | franck cuny <franck@lumberjaph.net> | 2010-06-08 11:26:24 +0200 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-06-08 11:26:24 +0200 |
commit | 80a47a62a1600dc3449f2d876c913f496f8d3907 (patch) | |
tree | 4dd0bb51937e17105aa3e1575ddb7fbf303c550a | |
parent | rewrote add anonymous method; move code to roles (diff) | |
download | net-http-console-80a47a62a1600dc3449f2d876c913f496f8d3907.tar.gz |
update name of api methods; fetch doc from method
-rw-r--r-- | lib/Net/HTTP/Console/Dispatcher/Help.pm | 57 |
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; |