lib/backticks/cli.rb in backticks-0.3.0 vs lib/backticks/cli.rb in backticks-0.3.1
- old
+ new
@@ -71,38 +71,30 @@
#
# @return [Array] list of String command-line options
def self.options(**opts)
flags = []
- # Transform opts into getopt-style command line parameters;
+ # Transform opts into golang flags-style command line parameters;
# append them to the command.
opts.each do |kw, arg|
if kw.length == 1
- # short-form option e.g. "-a" or "-x hello"
- pre='-'
- eql=' '
+ if arg == true
+ # true: boolean flag
+ flags << "-#{kw}"
+ elsif arg
+ # truthey: option that has a value
+ flags << "-#{kw}" << arg.to_s
+ else
+ # falsey: omit boolean flag
+ end
else
- # long-form option e.g. "--ask" or "--extra=hello"
kw = kw.to_s.gsub('_','-')
- pre='--'
- eql='='
- end
-
- # options can be single- or multi-valued; normalize the processing
- # of both by "upconverting" single options to an array or values.
- if arg.kind_of?(Array)
- values = arg
- else
- values = [arg]
- end
-
- values.each do |arg|
if arg == true
# true: boolean flag
- flags << "#{pre}#{kw}"
+ flags << "--#{kw}"
elsif arg
# truthey: option that has a value
- flags << "#{pre}#{kw}#{eql}#{arg}"
+ flags << "--#{kw}=#{arg}"
else
# falsey: omit boolean flag
end
end
end
\ No newline at end of file