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-fede-0.85.38 lib/cc/cli/help.rb
codeclimate-fede-0.85.37 lib/cc/cli/help.rb
codeclimate-fede-0.85.36 lib/cc/cli/help.rb
codeclimate-fede-0.85.35 lib/cc/cli/help.rb
codeclimate-fede-0.85.33 lib/cc/cli/help.rb
codeclimate-fede-0.85.32 lib/cc/cli/help.rb
codeclimate-fede-0.85.31 lib/cc/cli/help.rb
codeclimate-fede-0.85.30 lib/cc/cli/help.rb
codeclimate-fede-0.85.21 lib/cc/cli/help.rb
codeclimate-fede-0.85.24 lib/cc/cli/help.rb
codeclimate-fede-0.85.23 lib/cc/cli/help.rb
codeclimate-0.85.23 lib/cc/cli/help.rb
codeclimate-0.85.22 lib/cc/cli/help.rb
codeclimate-0.85.21 lib/cc/cli/help.rb
codeclimate-0.85.19 lib/cc/cli/help.rb
codeclimate-0.85.18 lib/cc/cli/help.rb
codeclimate-0.85.17 lib/cc/cli/help.rb
codeclimate-0.85.15 lib/cc/cli/help.rb
codeclimate-0.85.14 lib/cc/cli/help.rb
codeclimate-0.85.13 lib/cc/cli/help.rb