Method: Bolt::Config#normalize_overrides

Defined in:
lib/bolt/config.rb

#normalize_overrides(options) ⇒ Object

Transforms CLI options into a config hash that can be merged with default and loaded config.



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/bolt/config.rb', line 223

def normalize_overrides(options)
  opts = options.transform_keys(&:to_s)

  # Pull out config options. We need to add 'transport' and 'inventoryfile' as they're
  # not part of the OPTIONS hash but are valid options that can be set with CLI options
  overrides = opts.slice(*OPTIONS.keys, 'inventoryfile', 'transport')

  # Pull out transport config options
  TRANSPORT_CONFIG.each do |transport, config|
    overrides[transport] = opts.slice(*config.options)
  end

  overrides['trace'] = opts['trace'] if opts.key?('trace')

  # Validate the overrides that can have arbitrary values
  schema = {
    type:        Hash,
    properties:  CLI_OPTIONS.map { |opt| [opt, _ref: opt] }.to_h,
    definitions: OPTIONS.merge(INVENTORY_OPTIONS)
  }

  Bolt::Validator.new.validate(overrides.slice(*CLI_OPTIONS), schema, 'command line')

  overrides
end