lib/ordu.rb in ordu-0.0.2 vs lib/ordu.rb in ordu-0.0.3

- old
+ new

@@ -25,10 +25,11 @@ options ||= self.class.options commands ||= self.class.commands action ||= self.class.action options.each { |o| option!(*o) } commands.each { |c| command!(*c) } + on_tail(command_summary) if command_summary @action = action end # Parse options in order, and call commands for non-option arguments (if the # command exists). This is how programs are exected. @@ -38,9 +39,18 @@ if commands.key?(args.first) return commands[args.shift].parse!(args) end end run(*args) + end + + # A string which summarizes the commands - shown in the help + def command_summary + return if commands.empty? + w = commands.keys.map(&:length).max + lines = ["Available commands:"] + lines += commands.map { |k, v| " %-#{w}s %s" % [k, v.desc] } + lines.join("\n") end # Parses a new instance. Note that this must be the top-level, since you # can't supply a name. This is convenient for starting the parser from # scripts.