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
197 198 199 |
# File 'lib/dry/cli/command.rb', line 197 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.
325 326 327 328 329 |
# File 'lib/dry/cli/command.rb', line 325 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
67 68 69 |
# File 'lib/dry/cli/command.rb', line 67 def self.desc(description) @description = description end |
.example(*examples) ⇒ Object
Describe the usage of the command
103 104 105 |
# File 'lib/dry/cli/command.rb', line 103 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 || [] @options = base. || [] end base.extend ClassMethods end |
.option(name, options = {}) ⇒ Object
Command line option (aka optional argument)
311 312 313 |
# File 'lib/dry/cli/command.rb', line 311 def self.option(name, = {}) @options << 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.
339 340 341 |
# File 'lib/dry/cli/command.rb', line 339 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.
317 318 319 320 321 |
# File 'lib/dry/cli/command.rb', line 317 def self.params @_mutex.synchronize do (@arguments + @options).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.
333 334 335 |
# File 'lib/dry/cli/command.rb', line 333 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.
345 346 347 |
# File 'lib/dry/cli/command.rb', line 345 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.
359 360 361 |
# File 'lib/dry/cli/command.rb', line 359 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.
365 366 367 |
# File 'lib/dry/cli/command.rb', line 365 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.
351 352 353 354 355 |
# File 'lib/dry/cli/command.rb', line 351 def self.superclass_variable_dup(var) if superclass.instance_variable_defined?(var) superclass.instance_variable_get(var).dup end end |