Class: Yobi::ArgvBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/yobi/argv_builder.rb,
sig/yobi.rbs

Overview

:nodoc:

Constant Summary collapse

FLAGS =

Returns:

  • (Hash[Symbol, String])
Hash.new { |flags, name| flags[name] = "--#{name.to_s.tr("_", "-")}" }
SHORT_FLAGS =

Returns:

  • (Hash[Symbol, String])
Hash.new { |flags, name| flags[name] = "-#{name}" }

Instance Method Summary collapse

Constructor Details

#initializeArgvBuilder

Returns a new instance of ArgvBuilder.



8
9
10
11
# File 'lib/yobi/argv_builder.rb', line 8

def initialize
  @argv = []
  @end_of_options_called = false
end

Instance Method Details

#append(*values) ⇒ self

Parameters:

  • values (Object)

Returns:

  • (self)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yobi/argv_builder.rb', line 21

def append(*values)
  values.each do |v|
    case v
    in nil
    in String
      @argv << v
    in Enumerable
      append(*v)
    else
      @argv << v.to_s
    end
  end
  self
end

#end_of_optionsself

Returns:

  • (self)


53
54
55
56
57
58
59
# File 'lib/yobi/argv_builder.rb', line 53

def end_of_options
  raise "end_of_options already called - Restic only honors the first \"--\"" if @end_of_options_called

  @end_of_options_called = true
  @argv << "--"
  self
end

#flag(name, value = nil) ⇒ self

Parameters:

  • name (Symbol)
  • value (Object) (defaults to: nil)

Returns:

  • (self)


36
37
38
39
40
# File 'lib/yobi/argv_builder.rb', line 36

def flag(name, value = nil)
  @argv << FLAGS[name]
  @argv << value.to_s unless value.nil?
  self
end

#inspectObject



17
18
19
# File 'lib/yobi/argv_builder.rb', line 17

def inspect
  "#<#{self.class} #{@argv.inspect}>"
end

#repeat_flag(name, values) ⇒ self

Parameters:

  • name (Symbol)
  • values (Object)

Returns:

  • (self)


42
43
44
45
46
# File 'lib/yobi/argv_builder.rb', line 42

def repeat_flag(name, values)
  name = FLAGS[name]
  array_of_strings(values).each { |value| @argv << name << value }
  self
end

#short_flag(name) ⇒ self

Parameters:

  • name (Symbol)

Returns:

  • (self)


48
49
50
51
# File 'lib/yobi/argv_builder.rb', line 48

def short_flag(name)
  @argv << SHORT_FLAGS[name]
  self
end

#to_aArray[String]

Returns:

  • (Array[String])


13
14
15
# File 'lib/yobi/argv_builder.rb', line 13

def to_a
  @argv
end