Class: YARD::CLI::CommandParser
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/yard/cli/command_parser.rb |
Overview
This class parses a command name out of the yard ::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.
Class Attribute Summary
Class Method Summary
- .new ⇒ CommandParser constructor
-
.run(*args) ⇒ void
Convenience method to create a new
CommandParserand call #run
Instance Method Summary
-
#run(*args) ⇒ void
Runs the
Commandobject matching the command name of the first argument. - #commands private
- #list_commands private
Constructor Details
.new ⇒ CommandParser
# File 'lib/yard/cli/command_parser.rb', line 56
def initialize log.show_backtraces = false end
Class Attribute Details
.commands ⇒ Hash{Symbol => Command} (rw)
# File 'lib/yard/cli/command_parser.rb', line 27
attr_accessor :commands
.default_command ⇒ Symbol (rw)
# File 'lib/yard/cli/command_parser.rb', line 31
attr_accessor :default_command
Class Method Details
.run(*args) ⇒ void
This method returns an undefined value.
Convenience method to create a new CommandParser and call #run
# File 'lib/yard/cli/command_parser.rb', line 54
def self.run(*args) new.run(*args) end
Instance Method Details
#commands (private)
[ GitHub ]# File 'lib/yard/cli/command_parser.rb', line 80
def commands; self.class.commands end
#list_commands (private)
[ GitHub ]
#run(*args) ⇒ void
This method returns an undefined value.
Runs the Command object matching the command name of the first
argument.
# File 'lib/yard/cli/command_parser.rb', line 63
def run(*args) unless args == ['--help'] if args.empty? || args.first =~ /^-/ command_name = self.class.default_command else command_name = args.first.to_sym args.shift end if commands.key?(command_name) return commands[command_name].run(*args) end end list_commands end