Sha256: 8e3579fc17a129dfd4309f2e67a219a9f1cf676b6fdc3a7c979bab4e70b1703c

Contents?: true

Size: 892 Bytes

Versions: 125

Compression:

Stored size: 892 Bytes

Contents

module J1
  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)
          J1.logger.error "Error:",
                "Sorry, don't know what the '#{cmd}' command is."
          J1.logger.info  "Valid commands:", prog.commands.keys.join(", ")
        end
      end
    end
  end
end

Version data entries

125 entries across 125 versions & 3 rubygems

Version Path
j1-template-2022.0.2 lib/j1/commands/help.rb
j1-template-2022.0.1 lib/j1/commands/help.rb
j1-template-2022.0.0 lib/j1/commands/help.rb
j1-template-2021.3.2 lib/j1/commands/help.rb
j1-template-2021.3.1 lib/j1/commands/help.rb
j1-template-2021.3.0 lib/j1/commands/help.rb
j1-template-2021.2.12 lib/j1/commands/help.rb
j1-template-2021.2.11 lib/j1/commands/help.rb
j1-template-2021.2.10 lib/j1/commands/help.rb
j1-template-2021.2.9 lib/j1/commands/help.rb
j1-template-2021.2.8 lib/j1/commands/help.rb
j1-template-2021.2.7 lib/j1/commands/help.rb
j1-template-2021.2.6 lib/j1/commands/help.rb
j1-template-2021.2.5 lib/j1/commands/help.rb
j1-template-2021.2.4 lib/j1/commands/help.rb
j1-template-2021.2.3 lib/j1/commands/help.rb
j1-template-2021.2.2 lib/j1/commands/help.rb
j1-template-2021.2.1 lib/j1/commands/help.rb
j1-template-2021.2.0 lib/j1/commands/help.rb
j1-template-2021.1.29 lib/j1/commands/help.rb