Module: Facter::OptionsValidator
- Defined in:
- lib/facter/framework/core/options/options_validator.rb
Constant Summary collapse
- INVALID_PAIRS_RULES =
{ '--color' => '--no-color', '--json' => ['--no-json', '-y', '--yaml', '--hocon'], '--yaml' => ['--no-yaml', '-j', '--hocon'], '--hocon' => '--no-hocon', '-j' => ['--no-json', '--hocon'], '-y' => ['--no-yaml', '-j', '--hocon'], '--puppet' => ['--no-puppet', '--no-ruby', '--no-custom-facts'], '-p' => ['--no-puppet', '--no-ruby', '--no-custom-facts'], '--no-external-facts' => '--external-dir', '--custom-dir' => ['--no-custom-facts', '--no-ruby'] }.freeze
- DUPLICATED_OPTIONS_RULES =
{ '-j' => '--json', '-y' => '--yaml', '-p' => '--puppet', '-h' => '--help', '-v' => '--version', '-l' => '--log-level', '-d' => '--debug', '-c' => '--config' }.freeze
- LOG_LEVEL =
%i[none trace debug info warn error fatal].freeze
Class Method Summary collapse
- .conflicting_configs(options) ⇒ Object
- .validate(options) ⇒ Object
- .validate_configs(options) ⇒ Object
- .validate_log_options(options) ⇒ Object
- .write_error_and_exit(message) ⇒ Object
Class Method Details
.conflicting_configs(options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/facter/framework/core/options/options_validator.rb', line 53 def self.conflicting_configs() no_ruby = ![:ruby] no_custom_facts = ![:custom_facts] puppet = [:puppet] custom_dir = [:custom_dir].nil? ? false : [:custom_dir].any? default_external_dir = Facter::OptionStore.default_external_dir # --puppet/-p option adds an external directory and is not an explicitly # set external_dir from cli or config file default_external_dir += [Puppet[:pluginfactdest]] if puppet && const_defined?('Puppet') external_dir = if [:external_dir].nil? || [:external_dir].none? false else [:external_dir] != default_external_dir end [ { 'no-ruby' => no_ruby, 'custom-dir' => custom_dir }, { 'no-external-facts' => ![:external_facts], 'external-dir' => external_dir }, { 'no-custom-facts' => no_custom_facts, 'custom-dir' => custom_dir }, { 'no-ruby' => no_ruby, 'puppet' => puppet }, { 'no-custom-facts' => no_custom_facts, 'puppet' => puppet } ] end |
.validate(options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/facter/framework/core/options/options_validator.rb', line 20 def self.validate() DUPLICATED_OPTIONS_RULES.each do |key, value| if .include?(key) && .include?(value) write_error_and_exit("option #{value} cannot be specified more than once.") end end INVALID_PAIRS_RULES.each do |key, value| common_values = [value].flatten & if .include?(key) && common_values.any? write_error_and_exit("#{key} and #{common_values.first} options conflict: please specify only one.") end end end |
.validate_configs(options) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/facter/framework/core/options/options_validator.rb', line 43 def self.validate_configs() conflicting_configs().each do |op| next unless op.values[0] && op.values[1] = "#{op.keys[0]} and #{op.keys[1]} options conflict: please specify only one" write_error_and_exit() end () end |
.validate_log_options(options) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/facter/framework/core/options/options_validator.rb', line 76 def self.() # TODO: find a better way to do this return if [:debug] == true && [:log_level] == :debug return if [:verbose] == true && [:log_level] == :info return unless [[:debug], [:verbose], [:log_level] != Facter::DEFAULT_LOG_LEVEL] .count(true) > 1 = 'debug, verbose, and log-level options conflict: please specify only one.' write_error_and_exit() end |