Class: Yobi::ArgvBuilder
- Inherits:
-
Object
- Object
- Yobi::ArgvBuilder
- Defined in:
- lib/yobi/argv_builder.rb,
sig/yobi.rbs
Overview
:nodoc:
Constant Summary collapse
- FLAGS =
Hash.new { |flags, name| flags[name] = "--#{name.to_s.tr("_", "-")}" }
- SHORT_FLAGS =
Hash.new { |flags, name| flags[name] = "-#{name}" }
Instance Method Summary collapse
- #append(*values) ⇒ self
- #end_of_options ⇒ self
- #flag(name, value = nil) ⇒ self
-
#initialize ⇒ ArgvBuilder
constructor
A new instance of ArgvBuilder.
- #inspect ⇒ Object
- #repeat_flag(name, values) ⇒ self
- #short_flag(name) ⇒ self
- #to_a ⇒ Array[String]
Constructor Details
#initialize ⇒ ArgvBuilder
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
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_options ⇒ self
53 54 55 56 57 58 59 |
# File 'lib/yobi/argv_builder.rb', line 53 def 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
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 |
#inspect ⇒ Object
17 18 19 |
# File 'lib/yobi/argv_builder.rb', line 17 def inspect "#<#{self.class} #{@argv.inspect}>" end |
#repeat_flag(name, values) ⇒ 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
48 49 50 51 |
# File 'lib/yobi/argv_builder.rb', line 48 def short_flag(name) @argv << SHORT_FLAGS[name] self end |
#to_a ⇒ Array[String]
13 14 15 |
# File 'lib/yobi/argv_builder.rb', line 13 def to_a @argv end |