Class: Hanami::CLI::Command
- Inherits:
-
Object
- Object
- Hanami::CLI::Command
- Extended by:
- Forwardable
- Defined in:
- lib/hanami/cli/command.rb
Overview
Base class for commands
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
- #command_name ⇒ Object readonly private
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
Instance Method Summary collapse
-
#initialize(command_name:) ⇒ Command
constructor
private
A new instance of Command.
Constructor Details
#initialize(command_name:) ⇒ Command
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.
Returns a new instance of Command.
360 361 362 |
# File 'lib/hanami/cli/command.rb', line 360 def initialize(command_name:, **) @command_name = command_name end |
Instance Attribute Details
#command_name ⇒ Object (readonly)
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.
356 357 358 |
# File 'lib/hanami/cli/command.rb', line 356 def command_name @command_name end |
Class Method Details
.argument(name, options = {}) ⇒ Object
Specify an argument
197 198 199 |
# File 'lib/hanami/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.
323 324 325 326 327 |
# File 'lib/hanami/cli/command.rb', line 323 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/hanami/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/hanami/cli/command.rb', line 103 def self.example(*examples) @examples += examples.flatten 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.
13 14 15 16 |
# File 'lib/hanami/cli/command.rb', line 13 def self.inherited(base) super base.extend ClassMethods end |
.option(name, options = {}) ⇒ Object
Command line option (aka optional argument)
311 312 313 |
# File 'lib/hanami/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.
337 338 339 |
# File 'lib/hanami/cli/command.rb', line 337 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 |
# File 'lib/hanami/cli/command.rb', line 317 def self.params (@arguments + @options).uniq 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.
331 332 333 |
# File 'lib/hanami/cli/command.rb', line 331 def self.required_arguments arguments.select(&:required?) end |