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.85.27 lib/cc/cli/help.rb
codeclimate-0.85.26 lib/cc/cli/help.rb
codeclimate-0.85.25 lib/cc/cli/help.rb
codeclimate-0.85.24 lib/cc/cli/help.rb
codeclimate-fede-0.85.54 lib/cc/cli/help.rb
codeclimate-fede-0.85.53 lib/cc/cli/help.rb
codeclimate-fede-0.85.52 lib/cc/cli/help.rb
codeclimate-fede-0.85.51 lib/cc/cli/help.rb
codeclimate-fede-0.85.50 lib/cc/cli/help.rb
codeclimate-fede-0.85.49 lib/cc/cli/help.rb
codeclimate-fede-0.85.48 lib/cc/cli/help.rb
codeclimate-fede-0.85.47 lib/cc/cli/help.rb
codeclimate-fede-0.85.46 lib/cc/cli/help.rb
codeclimate-fede-0.85.45 lib/cc/cli/help.rb
codeclimate-fede-0.85.44 lib/cc/cli/help.rb
codeclimate-fede-0.85.43 lib/cc/cli/help.rb
codeclimate-fede-0.85.42 lib/cc/cli/help.rb
codeclimate-fede-0.85.41 lib/cc/cli/help.rb
codeclimate-fede-0.85.40 lib/cc/cli/help.rb
codeclimate-fede-0.85.39 lib/cc/cli/help.rb