Sha256: f6897b1d024b92d155c6bd910d0cc4b6e8377305a8227397d5847d85c51f339b

Contents?: true

Size: 1.33 KB

Versions: 123

Compression:

Stored size: 1.33 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)
        if (command = Command[command_name])
          say "Usage: codeclimate #{command.synopsis}\n"
          say "\n"
          say "#{command.help}\n"
          say "\n\n"
        else
          say "Unknown command: #{command_name}"
        end
      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

123 entries across 123 versions & 2 rubygems

Version Path
codeclimate-0.66.0 lib/cc/cli/help.rb
codeclimate-0.65.0 lib/cc/cli/help.rb
codeclimate-0.64.0 lib/cc/cli/help.rb
codeclimate-0.63.7 lib/cc/cli/help.rb
codeclimate-0.63.6 lib/cc/cli/help.rb
codeclimate-0.63.5 lib/cc/cli/help.rb
codeclimate-0.63.4 lib/cc/cli/help.rb
codeclimate-0.63.3 lib/cc/cli/help.rb
codeclimate-0.63.2 lib/cc/cli/help.rb
codeclimate-0.63.1 lib/cc/cli/help.rb
codeclimate-0.63.0 lib/cc/cli/help.rb
codeclimate-0.62.0 lib/cc/cli/help.rb
codeclimate-0.61.1 lib/cc/cli/help.rb
codeclimate-0.61.0 lib/cc/cli/help.rb
codeclimate-0.60.1 lib/cc/cli/help.rb
codeclimate-0.60.0 lib/cc/cli/help.rb
codeclimate-0.59.1 lib/cc/cli/help.rb
codeclimate-0.59.0 lib/cc/cli/help.rb
codeclimate-0.58.0 lib/cc/cli/help.rb
codeclimate-0.57.0 lib/cc/cli/help.rb