Sha256: 8eff834ce434242a3e6403573222da2220623501b42be539393396178fe364a2

Contents?: true

Size: 970 Bytes

Versions: 110

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true

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?
                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

        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
      end
    end
  end
end

Version data entries

110 entries across 110 versions & 1 rubygems

Version Path
j1-template-2024.3.19 lib/j1/commands/help.rb
j1-template-2024.3.18 lib/j1/commands/help.rb
j1-template-2024.3.17 lib/j1/commands/help.rb
j1-template-2024.3.16 lib/j1/commands/help.rb
j1-template-2024.3.15 lib/j1/commands/help.rb
j1-template-2024.3.14 lib/j1/commands/help.rb
j1-template-2024.3.13 lib/j1/commands/help.rb
j1-template-2024.3.12 lib/j1/commands/help.rb
j1-template-2024.2.1 lib/j1/commands/help.rb
j1-template-2024.2.0 lib/j1/commands/help.rb
j1-template-2024.1.5 lib/j1/commands/help.rb
j1-template-2024.1.4 lib/j1/commands/help.rb
j1-template-2024.1.3 lib/j1/commands/help.rb
j1-template-2024.1.2 lib/j1/commands/help.rb
j1-template-2024.1.1 lib/j1/commands/help.rb
j1-template-2024.1.0 lib/j1/commands/help.rb
j1-template-2024.0.3 lib/j1/commands/help.rb
j1-template-2024.0.2 lib/j1/commands/help.rb
j1-template-2024.0.1 lib/j1/commands/help.rb
j1-template-2024.0.0 lib/j1/commands/help.rb