Sha256: 220d237fc7793ae8a55266c221d8caf496852c3ac2d95f88e998b332081799a1

Contents?: true

Size: 919 Bytes

Versions: 3

Compression:

Stored size: 919 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

3 entries across 3 versions & 1 rubygems

Version Path
bunto-3.0.0 lib/bunto/commands/help.rb
bunto-2.0.0.pre lib/bunto/commands/help.rb
bunto-1.0.0 lib/bunto/commands/help.rb