lib/cmds/util/defaults.rb in cmds-0.2.2 vs lib/cmds/util/defaults.rb in cmds-0.2.3
- old
+ new
@@ -28,12 +28,29 @@
# what to join array option values with when using `array_mode = :join`
array_join_string: ',',
# what to do with false array values
false_mode: :omit,
- }.map {|k, v| [k, v.freeze]}.to_h
+
+ # Stick ENV var defs inline at beginning of command
+ env_mode: :inline,
+
+ # No additional environment
+ env: {},
+
+ # Don't change directories
+ chdir: nil,
+
+ # Don't asset (raise error if exit code is not 0)
+ assert: false,
+
+ # No input
+ input: nil,
+
+ }.map { |k, v| [k, v.freeze] }.to_h.freeze
+
# merge an method call options hash with common defaults for the module.
#
# this makes it easy to use the same defaults in many different methods
# without repeating the declarations everywhere.
#
@@ -49,23 +66,25 @@
# @return [Hash<Symbol, Object>]
# defaults to use in the method call.
#
def self.defaults opts, keys = '*', extras = {}
if keys == '*'
- DEFAULTS
+ DEFAULTS.dup
else
keys.
map {|key|
[key, DEFAULTS.fetch(key)]
}.
to_h
end.
- merge!(extras).
- merge!(opts)
+ merge!( extras ).
+ merge!( opts )
end
+
# proxy through to class method {Cmds.defaults}.
#
def defaults opts, keys = '*', extras = {}
self.class.defaults opts, keys, extras
end
+
end