moss

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 6d00d222e87858bc7f1bbf47a15bd1ae71e35bdd
parent ad2839962a7ffd0d7c257f25db8ad42c141a2864
Author: Daniel Barlow <dan@telent.net>
Date:   Fri, 13 Aug 2021 10:02:40 +0100

simplify alias handling

Diffstat:
Mfeatures/moss.feature | 3+++
Mmoss.rb | 13+++++++------
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/features/moss.feature b/features/moss.feature @@ -116,6 +116,9 @@ Feature: command-line password management And I see the string "Usage: moss \[command\] \[parameters\]" And I see the string "add a secret to the store" + When I run "moss kxdcjghlsdkjfhgslkdjg" + Then I see the string "unrecognised command. See \"moss help\"" + Scenario: argument checking When I run "moss show" Then it shows a usage message for "show" diff --git a/moss.rb b/moss.rb @@ -168,19 +168,20 @@ class CLI def link(ends) dest, src = ends.first - @@commands[dest] = { alias: src } + @@commands[dest] = { name: @@commands[src][:name] } end end def parse_arguments(argv) name = argv.first.to_sym args = argv.drop(1) - raise NoMethodError unless @@commands.key?(name) - command = @@commands[name] - if dst = command[:alias] - command = @@commands[dst] + begin + command = @@commands.fetch(name) + rescue KeyError + raise UsageError,"moss: unrecognised command. See \"moss help\"" end + arg_signature = method(command[:name]).parameters return [name, []] if arg_signature.empty? @@ -241,7 +242,7 @@ class CLI def usage command_texts = @@commands.map { |name, command| - if command[:name] + if command[:doc] format " %-40s - %s", describe_usage(name), command[:doc]