Class: Dry::CLI::Command
- Inherits:
-
Object
- Object
- Dry::CLI::Command
- Extended by:
- Forwardable
- Defined in:
- lib/dry/cli/command.rb
Overview
Base class for commands
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.argument(name, options = {}) ⇒ Object
Specify an argument.
- .default_params ⇒ Object private
-
.desc(description) ⇒ Object
Set the description of the command.
-
.example(*examples) ⇒ Object
Describe the usage of the command.
- .inherited(base) ⇒ Object private
-
.option(name, options = {}) ⇒ Object
Command line option (aka optional argument).
- .optional_arguments ⇒ Object private
- .params ⇒ Object private
- .required_arguments ⇒ Object private
- .subcommands ⇒ Object private
- .superclass_arguments ⇒ Object private
- .superclass_options ⇒ Object private
- .superclass_variable_dup(var) ⇒ Object private
Class Method Details
.argument(name, options = {}) ⇒ Object
Specify an argument
201 202 203 |
# File 'lib/dry/cli/command.rb', line 201 def self.argument(name, = {}) @arguments << Argument.new(name, ) end |
.default_params ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
329 330 331 332 333 |
# File 'lib/dry/cli/command.rb', line 329 def self.default_params params.each_with_object({}) do |param, result| result[param.name] = param.default unless param.default.nil? end end |
.desc(description) ⇒ Object
Set the description of the command
71 72 73 |
# File 'lib/dry/cli/command.rb', line 71 def self.desc(description) @description = description end |
.example(*examples) ⇒ Object
Describe the usage of the command
107 108 109 |
# File 'lib/dry/cli/command.rb', line 107 def self.example(*examples) @examples += examples.flatten(1) end |
.inherited(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dry/cli/command.rb', line 14 def self.inherited(base) super base.class_eval do @_mutex = Mutex.new @description = nil @examples = [] @subcommands = [] @arguments = base.superclass_arguments || [] = base. || [] end base.extend ClassMethods end |
.option(name, options = {}) ⇒ Object
Command line option (aka optional argument)
315 316 317 |
# File 'lib/dry/cli/command.rb', line 315 def self.option(name, = {}) << Option.new(name, ) end |
.optional_arguments ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
343 344 345 |
# File 'lib/dry/cli/command.rb', line 343 def self.optional_arguments arguments.reject(&:required?) end |
.params ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
321 322 323 324 325 |
# File 'lib/dry/cli/command.rb', line 321 def self.params @_mutex.synchronize do (@arguments + ).uniq end end |
.required_arguments ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
337 338 339 |
# File 'lib/dry/cli/command.rb', line 337 def self.required_arguments arguments.select(&:required?) end |
.subcommands ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
349 350 351 |
# File 'lib/dry/cli/command.rb', line 349 def self.subcommands subcommands end |
.superclass_arguments ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
363 364 365 |
# File 'lib/dry/cli/command.rb', line 363 def self.superclass_arguments superclass_variable_dup(:@arguments) end |
.superclass_options ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
369 370 371 |
# File 'lib/dry/cli/command.rb', line 369 def self. superclass_variable_dup(:@options) end |
.superclass_variable_dup(var) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
355 356 357 358 359 |
# File 'lib/dry/cli/command.rb', line 355 def self.superclass_variable_dup(var) if superclass.instance_variable_defined?(var) superclass.instance_variable_get(var).dup end end |