Sha256: 811319e4373ddde8eebbbc0b44ae6e865a681d64412d58ac8ef3f393b5751593

Contents?: true

Size: 1.55 KB

Versions: 22

Compression:

Stored size: 1.55 KB

Contents

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(22)} #{color(cmd.description, :info)}"
            end
          end
          say "\nrun `#$0 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.select do |cmd|
          !cmd.ancestors.include? CLI::ApiCommand
        end.sort_by {|c| c.command_name}
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
travis-1.11.1 lib/travis/cli/help.rb
travis-1.11.0 lib/travis/cli/help.rb
travis-1.10.1.travis.1341.9 lib/travis/cli/help.rb
travis-1.10.1.travis.1321.9 lib/travis/cli/help.rb
travis-1.10.1.travis.1312.9 lib/travis/cli/help.rb
travis-1.10.1.travis.1311.9 lib/travis/cli/help.rb
travis-1.10.1.travis.1305.9 lib/travis/cli/help.rb
travis-1.10.0 lib/travis/cli/help.rb
travis-1.9.2.travis.1304.9 lib/travis/cli/help.rb
travis-1.9.2.travis.1303.9 lib/travis/cli/help.rb
travis-1.10.0.pre.rc4 lib/travis/cli/help.rb
travis-1.10.0.pre.rc3 lib/travis/cli/help.rb
travis-1.10.0.pre.rc2 lib/travis/cli/help.rb
travis-1.9.2.travis.1288.9 lib/travis/cli/help.rb
travis-1.9.2.travis.1285.9 lib/travis/cli/help.rb
travis-1.9.2.travis.1279.9 lib/travis/cli/help.rb
travis-1.10.0.pre.rc1 lib/travis/cli/help.rb
travis-1.9.2.travis.1254.9 lib/travis/cli/help.rb
travis-1.9.2.travis.1236.9 lib/travis/cli/help.rb
travis-1.9.2.travis.1224.9 lib/travis/cli/help.rb