Sha256: b142c6f0b8013e8a38071d7419c5bb250ddc023a7d708ed479952c73fa1061bf

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

require "rainbow"

module CC
  module CLI
    class Help < Command
      ARGUMENT_LIST = "[command]".freeze
      SHORT_HELP = "Display help information.".freeze
      HELP = "#{SHORT_HELP}\n" \
        "\n" \
        "    no arguments   Show help summary for all commands.\n" \
        "    [command]      Show help for specific commands. Can be specified multiple times.".freeze

      def run
        if @args.any?
          @args.each do |command|
            show_help(command)
          end
        else
          show_help_summary
        end
      end

      private

      def show_help(command_name)
        command = Command[command_name]
        say "Usage: codeclimate #{command.synopsis}\n"
        say "\n"
        say "#{command.help}\n"
        say "\n\n"
      end

      def show_help_summary
        short_helps =
          Command.all.sort_by(&:command_name).map do |command|
            [command.synopsis, command.short_help]
          end.compact.to_h

        longest_command_length = short_helps.keys.map(&:length).max

        say "Usage: codeclimate COMMAND ...\n\nAvailable commands:\n"
        short_helps.each do |command, help|
          say format("    %-#{longest_command_length}s    %s\n", command, help)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
codeclimate-0.53.0 lib/cc/cli/help.rb
codeclimate-0.52.0 lib/cc/cli/help.rb
codeclimate-0.51.3 lib/cc/cli/help.rb
codeclimate-0.51.2 lib/cc/cli/help.rb
codeclimate-0.51.1 lib/cc/cli/help.rb
codeclimate-0.51.0 lib/cc/cli/help.rb
codeclimate-0.50.0 lib/cc/cli/help.rb
codeclimate-0.49.0 lib/cc/cli/help.rb
codeclimate-0.48.0 lib/cc/cli/help.rb
codeclimate-0.47.0 lib/cc/cli/help.rb
codeclimate-0.46.0 lib/cc/cli/help.rb