Class: HaveAPI::CLI::Command
- Inherits:
-
Object
- Object
- HaveAPI::CLI::Command
- Defined in:
- lib/haveapi/cli/command.rb
Class Attribute Summary collapse
-
.action ⇒ Object
readonly
Returns the value of attribute action.
-
.resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Attribute Summary collapse
-
#global_opts ⇒ Object
readonly
Returns the value of attribute global_opts.
Class Method Summary collapse
- .args(v = nil) ⇒ Object
- .cmd(resource, action = nil) ⇒ Object
- .desc(v = nil) ⇒ Object
- .handle?(resource, action) ⇒ Boolean
Instance Method Summary collapse
- #exec(args) ⇒ Object
-
#initialize(opts, client) ⇒ Command
constructor
A new instance of Command.
- #options(opts) ⇒ Object
Constructor Details
#initialize(opts, client) ⇒ Command
Returns a new instance of Command.
39 40 41 42 |
# File 'lib/haveapi/cli/command.rb', line 39 def initialize(opts, client) @global_opts = opts @api = client end |
Class Attribute Details
.action ⇒ Object (readonly)
Returns the value of attribute action.
4 5 6 |
# File 'lib/haveapi/cli/command.rb', line 4 def action @action end |
.resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'lib/haveapi/cli/command.rb', line 4 def resource @resource end |
Instance Attribute Details
#global_opts ⇒ Object (readonly)
Returns the value of attribute global_opts.
37 38 39 |
# File 'lib/haveapi/cli/command.rb', line 37 def global_opts @global_opts end |
Class Method Details
.args(v = nil) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/haveapi/cli/command.rb', line 14 def args(v = nil) if v @args = v else @args end end |
.cmd(resource, action = nil) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/haveapi/cli/command.rb', line 6 def cmd(resource, action = nil) @resource = resource.is_a?(::Array) ? resource : [resource] @resource.map! { |v| v.to_s } @action = action && action.to_s Cli.register_command(self) end |
.desc(v = nil) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/haveapi/cli/command.rb', line 23 def desc(v = nil) if v @desc = v else @desc end end |
.handle?(resource, action) ⇒ Boolean
32 33 34 |
# File 'lib/haveapi/cli/command.rb', line 32 def handle?(resource, action) resource == @resource && action == @action end |
Instance Method Details
#exec(args) ⇒ Object
48 49 50 |
# File 'lib/haveapi/cli/command.rb', line 48 def exec(args) raise NotImplementedError end |
#options(opts) ⇒ Object
44 45 46 |
# File 'lib/haveapi/cli/command.rb', line 44 def (opts) end |