Class: J1::Commands::Help
- Inherits:
-
J1::Command
- Object
- J1::Command
- J1::Commands::Help
- Defined in:
- lib/j1/commands/help.rb
Class Method Summary collapse
Methods inherited from J1::Command
Class Method Details
.init_with_program(prog) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/j1/commands/help.rb', line 8 def init_with_program(prog) prog.command(:help) do |c| c.syntax "help [subcommand]" c.description "Show the help message, optionally for a given subcommand" c.action do |args, _| cmd = (args.first || "").to_sym if args.empty? J1.logger.info prog.to_s elsif prog.has_command? cmd J1.logger.info prog.commands[cmd].to_s else invalid_command(prog, cmd) abort end end end end |
.invalid_command(prog, cmd) ⇒ Object
27 28 29 30 31 |
# File 'lib/j1/commands/help.rb', line 27 def invalid_command(prog, cmd) J1.logger.error "Error:", "Hmm... we don't know what the '#{cmd}' command is." J1.logger.info "Valid commands:", prog.commands.keys.join(", ") end |