class YARD::CLI::CommandParser

This class parses a command name out of the yard CLI command and calls that command in the form:

$ yard command_name [options]

If no command or arguments are specified, or if the arguments immediately begin with a --opt (not --help), the {default_command} will be used (which itself defaults to :doc).

Adding a Command

To add a custom command via plugin, create a mapping in {commands} from the Symbolic command name to the {Command} class that implements the command. To implement a command, see the documentation for the {Command} class.

@see Command @see commands @see ::default_command

Attributes

commands[RW]

@return [Hash{Symbol => Command}] the mapping of command names to

command classes to parse the user command.
default_command[RW]

@return [Symbol] the default command name to use when no options

are specified or

Public Class Methods

new() click to toggle source
# File lib/yard/cli/command_parser.rb, line 55
def initialize
  log.show_backtraces = false
end
run(*args) click to toggle source

Convenience method to create a new CommandParser and call {#run} @return (see run)

# File lib/yard/cli/command_parser.rb, line 53
def self.run(*args) new.run(*args) end

Public Instance Methods

run(*args) click to toggle source

Runs the {Command} object matching the command name of the first argument. @return [void]

# File lib/yard/cli/command_parser.rb, line 62
def run(*args)
  unless args == ['--help']
    if args.size == 0 || args.first =~ /^-/
      command_name = self.class.default_command
    else
      command_name = args.first.to_sym
      args.shift
    end
    if commands.has_key?(command_name)
      return commands[command_name].run(*args)
    end
  end
  list_commands
end

Private Instance Methods

commands() click to toggle source
# File lib/yard/cli/command_parser.rb, line 79
def commands; self.class.commands end
list_commands() click to toggle source
# File lib/yard/cli/command_parser.rb, line 81
def list_commands
  log.puts "Usage: yard <command> [options]"
  log.puts
  log.puts "Commands:"
  commands.keys.sort_by {|k| k.to_s }.each do |command_name|
    command = commands[command_name].new
    log.puts "%-8s %s" % [command_name, command.description]
  end
end