Method: Beaker::Command#options_string
- Defined in:
- lib/beaker/command.rb
#options_string(opts = @options) ⇒ String
Note:
Why no. Not the least bit Unixy, why do you ask?
Returns String of the options and flags for command.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/beaker/command.rb', line 90 def opts = @options flags = [] = opts.dup .each_key do |key| if [key] == nil flags << key .delete(key) end end short_flags, long_flags = flags.partition {|flag| flag.to_s.length == 1 } parsed_short_flags = short_flags.map {|f| "-#{f}" } parsed_long_flags = long_flags.map {|f| "--#{f}" } short_opts, long_opts = {}, {} .each_key do |key| if key.to_s.length == 1 short_opts[key] = [key] else long_opts[key] = [key] end end parsed_short_opts = short_opts.map {|k,v| "-#{k}=#{v}" } parsed_long_opts = long_opts.map {|k,v| "--#{k}=#{v}" } return (parsed_short_flags + parsed_long_flags + parsed_short_opts + parsed_long_opts).join(' ') end |