Sha256: 58d9df4a6521de1426b5469888d85012336652d22cfec312fe77392dbc4e16cb

Contents?: true

Size: 1.6 KB

Versions: 5

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'travis/cli'

module Travis
  module CLI
    class Help < Command
      description 'helps you out when in dire need of information'

      CommandGroup = Struct.new(:cmds, :header)

      def run(command = nil)
        if command
          say CLI.command(command).new.help
        else
          api_cmds   = CommandGroup.new(api_commands,   'API commands')
          repo_cmds  = CommandGroup.new(repo_commands,  'Repo commands')
          other_cmds = CommandGroup.new(other_commands, 'non-API commands')

          say "Usage: travis COMMAND ...\n\nAvailable commands:\n\n"
          [other_cmds, api_cmds, repo_cmds].each do |cmd_grp|
            say "    #{cmd_grp.header}"
            cmd_grp.cmds.each do |cmd|
              say "        #{color(cmd.command_name, :command).ljust(25)} #{color(cmd.description, :info)}"
            end
          end
          say "\nrun `#{$PROGRAM_NAME} help COMMAND` for more info"
        end
      end

      def cmd_group_header(title)
        say "    #{color(title, :green)}"
      end

      def api_commands
        CLI.commands.select do |cmd|
          cmd.ancestors.include?(CLI::ApiCommand) &&
            !cmd.ancestors.include?(CLI::RepoCommand)
        end.sort_by { |c| c.command_name }
      end

      def repo_commands
        CLI.commands.select do |cmd|
          cmd.ancestors.include? CLI::RepoCommand
        end.sort_by { |c| c.command_name }
      end

      def other_commands
        CLI.commands.reject do |cmd|
          cmd.ancestors.include? CLI::ApiCommand
        end.sort_by { |c| c.command_name }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
travis-1.14.0 lib/travis/cli/help.rb
travis-1.13.3 lib/travis/cli/help.rb
travis-1.13.2 lib/travis/cli/help.rb
travis-1.13.1 lib/travis/cli/help.rb
travis-1.13.0 lib/travis/cli/help.rb