Class: Gat::Dependence::Argument

Inherits:
Base
  • Object
show all
Defined in:
lib/gat/dependence/argument.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #description, #name, #operation

Instance Method Summary collapse

Constructor Details

#initialize(name, config, operation) ⇒ Argument

Returns a new instance of Argument.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gat/dependence/argument.rb', line 12

def initialize(name, config, operation)
	
	super(name, config, operation)
	# by default, argument is command line
	@type     = @config['type']     || 'command_line'
	@optional = @config['optional'] || false
	@prefix	= @config['prefix']   || nil
	
	@@argument_position ||= 0
	@position = ( @@argument_position += 1 )

end

Instance Attribute Details

#optionalObject (readonly)

Returns the value of attribute optional.



6
7
8
# File 'lib/gat/dependence/argument.rb', line 6

def optional
  @optional
end

#positionObject (readonly)

Returns the value of attribute position.



5
6
7
# File 'lib/gat/dependence/argument.rb', line 5

def position
  @position
end

#prefixObject (readonly)

Returns the value of attribute prefix.



7
8
9
# File 'lib/gat/dependence/argument.rb', line 7

def prefix
  @prefix
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/gat/dependence/argument.rb', line 8

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/gat/dependence/argument.rb', line 10

def value
  @value
end

Instance Method Details

#evalueObject

Argument must come



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gat/dependence/argument.rb', line 26

def evalue
	# command line arguments
	if self.type == 'command_line' and self.operation.gatget.arguments.any? and self.operation.gatget.arguments[self.position]
	  
	  # ToDo => add prefix to arguments
	  # if self.position == 'prefix'
	    #prefix_position = self.operation.gatget.arguments.index(self.prefix)
	    #self.value	  = self.operation.gatget.arguments[
	  # else
	    self.value = self.operation.gatget.arguments[self.position]
	  # end
	  
	# get arguments
	elsif self.type == 'get' or self.type == 'get_password'
	  
	  # log direct question
	  get_question = self.config['get_question'] || "Gatget need a value for argument #{ self.name } (#{ self.description })"
	  
	  self.operation.gatget.logger.log("direct", 'get_argument', get_question)
 
	  system "stty -echo" if self.type == 'get_password'   # remove letter echo

	  self.value = $stdin.gets.chomp
	  
	  system "stty echo" if self.type == 'get_password'   # remove letter echo
	  
	# argument missing but not required
	elsif self.optional
	  self.operation.gatget.logger.log("info", "missing argument #{ self.name } at operation #{ self.operation.name }. Argument is marked as optional")
	else  
	  raise GatgetArgumentException.new("Missing dependence argument #{ self.name } (@#{ self.type}) ", "evalue_program_dependence")
	end
end