Class: Eco::CLI::Scripting::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/cli/scripting/argument.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, with_param: false) ⇒ Argument

Returns a new instance of Argument.



14
15
16
17
# File 'lib/eco/cli/scripting/argument.rb', line 14

def initialize(key, with_param: false)
  @key        = key
  @with_param = !!with_param
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/eco/cli/scripting/argument.rb', line 6

def key
  @key
end

Class Method Details

.is_modifier?(value) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/eco/cli/scripting/argument.rb', line 9

def is_modifier?(value)
 value&.start_with?("-")
end

Instance Method Details

#args_slice(*args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/eco/cli/scripting/argument.rb', line 19

def args_slice(*args)
  #pp "known arg '#{key}' => included? #{args.include?(key)}"
  return args unless args.include?(key)
  i = args.index(key)
  j = with_param?? i+1 : i
  args - args.slice(i..j)
end

#with_param!Object



27
28
29
# File 'lib/eco/cli/scripting/argument.rb', line 27

def with_param!
  @with_param = true
end

#with_param?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/eco/cli/scripting/argument.rb', line 31

def with_param?
  @with_param
end