Class: VagrantPlugins::DevCommands::Model::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/devcommands/model/command.rb

Overview

Definition of an executable command

Constant Summary collapse

PARAM_PARSER =
VagrantPlugins::DevCommands::ParamParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Command

Returns a new instance of Command.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vagrant/devcommands/model/command.rb', line 12

def initialize(spec)
  @name = spec[:name]

  @flags      = spec[:flags] || {}
  @parameters = spec[:parameters] || {}
  @script     = spec[:script]
  @tty        = spec[:tty] == true

  @machine = spec[:machine]
  @desc    = spec[:desc]
  @help    = spec[:help]
  @usage   = spec[:usage]
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def desc
  @desc
end

#flagsObject (readonly)

Returns the value of attribute flags.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def flags
  @flags
end

#helpObject (readonly)

Returns the value of attribute help.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def help
  @help
end

#machineObject (readonly)

Returns the value of attribute machine.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def machine
  @machine
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def parameters
  @parameters
end

#scriptObject (readonly)

Returns the value of attribute script.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def script
  @script
end

#ttyObject (readonly)

Returns the value of attribute tty.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def tty
  @tty
end

#usageObject (readonly)

Returns the value of attribute usage.



10
11
12
# File 'lib/vagrant/devcommands/model/command.rb', line 10

def usage
  @usage
end

Instance Method Details

#run_script(argv) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/vagrant/devcommands/model/command.rb', line 26

def run_script(argv)
  param_parser = PARAM_PARSER.new
  params       = param_parser.parse!(self, argv)

  script = @script
  script = eval_script_proc(script, params) if script.is_a?(Proc)

  (script % params).strip
end