class Git::ArgsBuilder
@api private
supported options are provided based on the map.
an array of command-line arguments. Also validates that only
Takes a hash of user options and a declarative map and produces
def self.build(opts, option_map)
def self.build(opts, option_map) validate!(opts, option_map) new(opts, option_map).build end
def self.check_for_missing_required_option!(opts, config)
def self.check_for_missing_required_option!(opts, config) g[:required] ig[:keys].any? { |k| opts.key?(k) } ded , "Missing required option: #{config[:keys].first}"
def self.validate!(opts, option_map)
def self.validate!(opts, option_map) validate_unsupported_keys!(opts, option_map) validate_configured_options!(opts, option_map) end
def self.validate_configured_options!(opts, option_map)
def self.validate_configured_options!(opts, option_map) |config| g[:keys] # Skip static flags _required_option!(opts, config) alue!(opts, config)
def self.validate_option_value!(opts, config)
def self.validate_option_value!(opts, config) :validator] ator keys].find { |k| opts.key?(k) } key # Don't validate if the user didn't provide the option .call(opts[user_key]) , "Invalid value for option: #{user_key}"
def self.validate_unsupported_keys!(opts, option_map)
def self.validate_unsupported_keys!(opts, option_map) tion_map.flat_map { |config| config[:keys] }.compact opts.keys - all_valid_keys ed_keys.empty? , "Unsupported options: #{unsupported_keys.map(&:inspect).join(', ')}"
def build
def build @option_map.flat_map do |config| type = config[:type] next config[:flag] if type == :static key = config[:keys].find { |k| @opts.key?(k) } next [] unless key build_arg_for_option(config, @opts[key]) end.compact end
def build_arg_for_option(config, value)
def build_arg_for_option(config, value) builder = ARG_BUILDERS[config[:type]] builder&.call(config, value) || [] end
def initialize(opts, option_map)
def initialize(opts, option_map) @opts = opts @option_map = option_map end