Style
This commit is contained in:
@@ -25,11 +25,10 @@ module Mrsk::Utils
|
|||||||
|
|
||||||
# Returns a list of shell-dashed option arguments. If the value is true, it's treated like a value-less option.
|
# Returns a list of shell-dashed option arguments. If the value is true, it's treated like a value-less option.
|
||||||
def optionize(args, with: nil)
|
def optionize(args, with: nil)
|
||||||
flattened_args = flatten_args args
|
|
||||||
options = if with
|
options = if with
|
||||||
flattened_args.collect { |(key, value)| value == true ? "--#{key}" : "--#{key}#{with}#{escape_shell_value(value)}" }
|
flatten_args(args).collect { |(key, value)| value == true ? "--#{key}" : "--#{key}#{with}#{escape_shell_value(value)}" }
|
||||||
else
|
else
|
||||||
flattened_args.collect { |(key, value)| [ "--#{key}", value == true ? nil : escape_shell_value(value) ] }
|
flatten_args(args).collect { |(key, value)| [ "--#{key}", value == true ? nil : escape_shell_value(value) ] }
|
||||||
end
|
end
|
||||||
|
|
||||||
options.flatten.compact
|
options.flatten.compact
|
||||||
@@ -37,7 +36,7 @@ module Mrsk::Utils
|
|||||||
|
|
||||||
# Flattens a one-to-many structure into an array of two-element arrays each containing a key-value pair
|
# Flattens a one-to-many structure into an array of two-element arrays each containing a key-value pair
|
||||||
def flatten_args(args)
|
def flatten_args(args)
|
||||||
args.flat_map { |key, value| value.respond_to?('map') ? value.map { |entry| [key, entry] }: [[key, value]] }
|
args.flat_map { |key, value| value.try(:map) { |entry| [key, entry] } || [ [ key, value ] ] }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Copied from SSHKit::Backend::Abstract#redact to be available inside Commands classes
|
# Copied from SSHKit::Backend::Abstract#redact to be available inside Commands classes
|
||||||
|
|||||||
Reference in New Issue
Block a user