Method: Beaker::Command#initialize

Defined in:
lib/beaker/command.rb

#initialize(command, args = [], options = {}) ⇒ Command

Note:

For backwards compatability we must support any number of strings or symbols (or arrays of strings an symbols) and essentially ensure they are in a flattened array, coerced to strings, and call #join(‘ ’) on it. We have options for the command line invocation that must be turned into ‘–key=value’ and similarly joined as well as a hash of environment key value pairs, and finally we need a hash of options to control the default envs that are included.

Returns a new instance of Command.

Examples:

Recommended usage programmatically:

Command.new('git add', files, :patch => true, 'ENV' => {'PATH' => '/opt/csw/bin'})

My favorite example of a signature that we must maintain

Command.new('puppet', :resource, 'scheduled_task', name,
            [ 'ensure=present',
              'command=c:\\\\windows\\\\system32\\\\notepad2.exe',
              "arguments=args-#{name}" ] )

Parameters:

  • command (String)

    The program to call, either an absolute path or one in the PATH (can be overridden)

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

    These are addition arguments to the command

  • options (Hash) (defaults to: {})

    These are addition options to the command. They will be added in “–key=value” after the command but before the arguments. There is a special key, ‘ENV’, that won’t be used as a command option, but instead can be used to set any default environment variables



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/beaker/command.rb', line 47

def initialize command, args = [], options = {}
  @command = command
  @options = options
  @args    = args
  @environment = {}
  @cmdexe = @options.delete(:cmdexe) || false
  @prepend_cmds = @options.delete(:prepend_cmds) || nil

  # this is deprecated and will not allow you to use a command line
  # option of `--environment`, please use ENV instead.
  [:ENV, :environment, 'environment', 'ENV'].each do |k|
     if @options[k].is_a?(Hash)
       @environment = @environment.merge(@options.delete(k))
     end
  end

end