Module: Bosh::Cli::CommandDiscovery

Included in:
Bosh::Cli::Command::Base
Defined in:
lib/cli/command_discovery.rb

Instance Method Summary collapse

Instance Method Details

#desc(string) ⇒ Object



10
11
12
# File 'lib/cli/command_discovery.rb', line 10

def desc(string)
  @desc = string
end

#method_added(method_name) ⇒ Object

Parameters:

  • method_name (Symbol)

    Method name



19
20
21
22
23
24
25
26
27
28
# File 'lib/cli/command_discovery.rb', line 19

def method_added(method_name)
  if @usage && @desc
    @options ||= []
    method = instance_method(method_name)
    register_command(method, @usage, @desc, @options)
  end
  @usage = nil
  @desc = nil
  @options = []
end

#option(name, *args) ⇒ Object



14
15
16
# File 'lib/cli/command_discovery.rb', line 14

def option(name, *args)
  (@options ||= []) << [name, args]
end

#register_command(method, usage, desc, options = []) ⇒ Object

Parameters:

  • method (UnboundMethod)

    Method implementing the command

  • usage (String)

    Command usage (used to parse command)

  • desc (String)

    Command description

  • options (Array) (defaults to: [])

    Command options



34
35
36
37
# File 'lib/cli/command_discovery.rb', line 34

def register_command(method, usage, desc, options = [])
  command = CommandHandler.new(self, method, usage, desc, options)
  Bosh::Cli::Config.register_command(command)
end

#usage(string = nil) ⇒ Object



6
7
8
# File 'lib/cli/command_discovery.rb', line 6

def usage(string = nil)
  @usage = string
end