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.78.0 lib/cc/cli/help.rb
codeclimate-0.77.0 lib/cc/cli/help.rb
codeclimate-0.76.0 lib/cc/cli/help.rb
codeclimate-0.75.0 lib/cc/cli/help.rb
codeclimate-0.74.0 lib/cc/cli/help.rb
codeclimate-0.73.0 lib/cc/cli/help.rb
codeclimate-0.72.0 lib/cc/cli/help.rb
codeclimate-0.71.2 lib/cc/cli/help.rb
codeclimate-0.71.1 lib/cc/cli/help.rb
codeclimate-0.71.0 lib/cc/cli/help.rb
codeclimate-0.70.6 lib/cc/cli/help.rb
codeclimate-0.70.5 lib/cc/cli/help.rb
codeclimate-0.70.4 lib/cc/cli/help.rb
codeclimate-0.70.3 lib/cc/cli/help.rb
codeclimate-0.70.2 lib/cc/cli/help.rb
codeclimate-0.70.1 lib/cc/cli/help.rb
codeclimate-0.70.0 lib/cc/cli/help.rb
codeclimate-0.69.0 lib/cc/cli/help.rb
codeclimate-0.68.0 lib/cc/cli/help.rb
codeclimate-0.67.0 lib/cc/cli/help.rb