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.96.0 lib/cc/cli/help.rb
codeclimate-0.95.0 lib/cc/cli/help.rb
codeclimate-0.94.1 lib/cc/cli/help.rb
codeclimate-0.94.0 lib/cc/cli/help.rb
codeclimate-0.93.0 lib/cc/cli/help.rb
codeclimate-0.92.1 lib/cc/cli/help.rb
codeclimate-0.92.0 lib/cc/cli/help.rb
codeclimate-0.91.0 lib/cc/cli/help.rb
codeclimate-0.90.0 lib/cc/cli/help.rb
codeclimate-0.89.0 lib/cc/cli/help.rb
codeclimate-0.88.0 lib/cc/cli/help.rb
codeclimate-0.87.5 lib/cc/cli/help.rb
codeclimate-0.87.4 lib/cc/cli/help.rb
codeclimate-0.87.3 lib/cc/cli/help.rb
codeclimate-0.87.2 lib/cc/cli/help.rb
codeclimate-0.87.1 lib/cc/cli/help.rb
codeclimate-0.87.0 lib/cc/cli/help.rb
codeclimate-0.86.0 lib/cc/cli/help.rb
codeclimate-0.85.29 lib/cc/cli/help.rb
codeclimate-0.85.28 lib/cc/cli/help.rb