Class: Cogy::Command
- Inherits:
-
Object
- Object
- Cogy::Command
- Defined in:
- lib/cogy/command.rb
Overview
Instance Attribute Summary collapse
- #args ⇒ Array readonly
- #desc ⇒ String readonly
- #examples ⇒ String readonly
- #handler ⇒ Proc readonly
- #long_desc ⇒ String readonly
- #name ⇒ String readonly
- #opts ⇒ Hash{Symbol=>Hash} readonly
- #rules ⇒ Array readonly
- #template ⇒ String readonly
Instance Method Summary collapse
-
#formatted_args ⇒ String
The command arguments suitable for conversion to YAML for displaying in a bundle config.
-
#formatted_opts ⇒ Hash
The command options suitable for conversion to YAML for displaying in a bundle config.
- #initialize(name, handler, args: [], opts: {}, desc:, long_desc: nil, examples: nil, rules: nil, template: nil) ⇒ Command constructor
-
#register! ⇒ self
Registers a command.
Constructor Details
#initialize(name, handler, args: [], opts: {}, desc:, long_desc: nil, examples: nil, rules: nil, template: nil) ⇒ Command
This is typically used via Cogy.on which also registers the newly created Cogy::Command.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cogy/command.rb', line 55 def initialize(name, handler, args: [], opts: {}, desc:, long_desc: nil, examples: nil, rules: nil, template: nil) @name = name.to_s @handler = handler @args = [args].flatten.map!(&:to_s) @opts = opts.with_indifferent_access @desc = desc @long_desc = long_desc @examples = examples @rules = rules || ["allow"] @template = template validate_opts end |
Instance Attribute Details
#args ⇒ Array (readonly)
14 15 16 |
# File 'lib/cogy/command.rb', line 14 def args @args end |
#desc ⇒ String (readonly)
20 21 22 |
# File 'lib/cogy/command.rb', line 20 def desc @desc end |
#examples ⇒ String (readonly)
26 27 28 |
# File 'lib/cogy/command.rb', line 26 def examples @examples end |
#handler ⇒ Proc (readonly)
11 12 13 |
# File 'lib/cogy/command.rb', line 11 def handler @handler end |
#long_desc ⇒ String (readonly)
23 24 25 |
# File 'lib/cogy/command.rb', line 23 def long_desc @long_desc end |
#name ⇒ String (readonly)
8 9 10 |
# File 'lib/cogy/command.rb', line 8 def name @name end |
#opts ⇒ Hash{Symbol=>Hash} (readonly)
17 18 19 |
# File 'lib/cogy/command.rb', line 17 def opts @opts end |
#rules ⇒ Array (readonly)
29 30 31 |
# File 'lib/cogy/command.rb', line 29 def rules @rules end |
#template ⇒ String (readonly)
32 33 34 |
# File 'lib/cogy/command.rb', line 32 def template @template end |
Instance Method Details
#formatted_args ⇒ String
Returns the command arguments suitable for conversion to YAML for displaying in a bundle config.
86 87 88 |
# File 'lib/cogy/command.rb', line 86 def formatted_args args.map { |a| "<#{a}>" }.join(" ") end |
#formatted_opts ⇒ Hash
Returns the command options suitable for conversion to YAML for displaying in a bundle config.
92 93 94 95 96 |
# File 'lib/cogy/command.rb', line 92 def formatted_opts # Convert to Hash in order to get rid of HashWithIndifferentAccess, # otherwise the resulting YAML will contain garbage. opts.to_hash end |