Class: HaveAPI::CLI::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/cli/command.rb

Direct Known Subclasses

HaveAPI::CLI::Commands::ActionStateWait

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.actionObject (readonly)

Returns the value of attribute action.



4
5
6
# File 'lib/haveapi/cli/command.rb', line 4

def action
  @action
end

.resourceObject (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_optsObject (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!(&: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

Returns:

  • (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

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/haveapi/cli/command.rb', line 46

def exec(args)
  raise NotImplementedError
end

#options(opts) ⇒ Object



44
# File 'lib/haveapi/cli/command.rb', line 44

def options(opts); end