Class: Swat::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/swat.rb

Overview

Parameters parsing helper class

Assumes the first parameter to be the execution mode (dryrun or execute) Assumes the second parameter to be the script name Captures the rest as arguments that are piped in to the script

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV.clone) ⇒ Parameters

Returns a new instance of Parameters.



83
84
85
86
87
88
89
# File 'lib/swat.rb', line 83

def initialize(args = ARGV.clone)
  @args = args
  @execution_mode = @args.shift
  @command = @args.shift
  fail "Execution mode is mandatory" if @execution_mode.nil?
  fail "No command was specified" if @command.nil?
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



81
82
83
# File 'lib/swat.rb', line 81

def args
  @args
end

#commandObject

Returns the value of attribute command.



81
82
83
# File 'lib/swat.rb', line 81

def command
  @command
end

#execution_modeObject

Returns the value of attribute execution_mode.



81
82
83
# File 'lib/swat.rb', line 81

def execution_mode
  @execution_mode
end

Instance Method Details

#to_sObject



91
92
93
# File 'lib/swat.rb', line 91

def to_s
  "#{@execution_mode} #{@command} #{@args.inspect}"
end