Sha256: ea90cef7e8b788c1dff279ee4db6ddc5ac2097a371bc94482029e378d145bda2

Contents?: true

Size: 936 Bytes

Versions: 2

Compression:

Stored size: 936 Bytes

Contents

module Bunto
  module Commands
    class Help < Command
      class << self
        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?
                puts prog
              elsif prog.has_command? cmd
                puts prog.commands[cmd]
              else
                invalid_command(prog, cmd)
                abort
              end
            end
          end
        end

        def invalid_command(prog, cmd)
          Bunto.logger.error "Error:",
                "Hmm... we don't know what the '#{cmd}' command is."
          Bunto.logger.info  "Valid commands:", prog.commands.keys.join(", ")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bunto-3.4.5 lib/bunto/commands/help.rb
bunto-3.2.1 lib/bunto/commands/help.rb