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

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

Overview

Definition of an executable command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Command

Returns a new instance of Command.



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

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

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

  @machine = spec[:machine] || spec[:box]
  @desc    = spec[:desc]
  @help    = spec[:help]
  @usage   = spec[:usage]

  @deprecated_box_config = spec.key?(:box)
end

Instance Attribute Details

#deprecated_box_configObject (readonly)

Returns the value of attribute deprecated_box_config.



19
20
21
# File 'lib/vagrant/devcommands/model/command.rb', line 19

def deprecated_box_config
  @deprecated_box_config
end

#descObject (readonly)

Returns the value of attribute desc.



15
16
17
# File 'lib/vagrant/devcommands/model/command.rb', line 15

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.



16
17
18
# File 'lib/vagrant/devcommands/model/command.rb', line 16

def help
  @help
end

#machineObject (readonly)

Returns the value of attribute machine.



14
15
16
# File 'lib/vagrant/devcommands/model/command.rb', line 14

def machine
  @machine
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/vagrant/devcommands/model/command.rb', line 8

def name
  @name
end

#parametersObject (readonly)

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

#scriptObject (readonly)

Returns the value of attribute script.



12
13
14
# File 'lib/vagrant/devcommands/model/command.rb', line 12

def script
  @script
end

#usageObject (readonly)

Returns the value of attribute usage.



17
18
19
# File 'lib/vagrant/devcommands/model/command.rb', line 17

def usage
  @usage
end

Instance Method Details

#run_script(argv) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/vagrant/devcommands/model/command.rb', line 36

def run_script(argv)
  script = @script
  script = script.call if script.is_a?(Proc)

  opts = {}
  opts = parse_argv(argv) unless @flags.empty? && @parameters.empty?

  (script % opts).strip
end