Module: Docker::CLI::Getopt
- Defined in:
- lib/docker/cli.rb
Overview
Translate a series Ruby positional and keyword arguments into Docker command- parameters consisting of words and options.
Each positional argument can be a Hash, an Array, or another object. They are handled as follows:
- Hash is translated to a sequence of options; see #options
- Array is appended to the command line as a sequence of words
- other objects are turned into a string with #to_s and appended to the command line as a
single word
Class Method Summary collapse
- .convert_option(option_name, option_value) ⇒ Object
- .extract_parameter(item) ⇒ Object
- .options(kwargs = {}) ⇒ Object
- .parameters(*sugar) ⇒ Object
- .process_list_option(flag, option_value) ⇒ Object
- .process_non_null_option(flag, option_value) ⇒ Object
Class Method Details
.convert_option(option_name, option_value) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/docker/cli.rb', line 42 def self.convert_option(option_name, option_value) flag = (option_name.length == 1) ? "-#{option_name}" : "--#{option_name}" return [flag] if option_value == true return process_list_option flag, option_value if option_value.is_a? Array return process_non_null_option flag, option_value if option_value end |
.extract_parameter(item) ⇒ Object
30 31 32 33 34 |
# File 'lib/docker/cli.rb', line 30 def self.extract_parameter(item) return item.map(&:to_s) if item.is_a? Array return (item) if item.is_a? Hash [item.to_s] end |
.options(kwargs = {}) ⇒ Object
36 37 38 39 40 |
# File 'lib/docker/cli.rb', line 36 def self.(kwargs = {}) # Transform opts into golang flags-style command line parameters; # append them to the command. kwargs.map { |kw, arg| convert_option kw, arg }.compact.flatten end |
.parameters(*sugar) ⇒ Object
24 25 26 27 28 |
# File 'lib/docker/cli.rb', line 24 def self.parameters(*sugar) sugar.each_with_object [] do |item, argv| argv.concat extract_parameter(item) end end |
.process_list_option(flag, option_value) ⇒ Object
49 50 51 52 53 |
# File 'lib/docker/cli.rb', line 49 def self.process_list_option(flag, option_value) option_value.map do |value_item| process_non_null_option flag, value_item if value_item end.compact.flatten end |
.process_non_null_option(flag, option_value) ⇒ Object
55 56 57 58 59 |
# File 'lib/docker/cli.rb', line 55 def self.process_non_null_option(flag, option_value) is_long_flag = flag[0..1] == '--' return "#{flag}=#{option_value}" if is_long_flag [flag, option_value.to_s] end |