Module: RFacter::Config
- Defined in:
- lib/rfacter/config.rb,
lib/rfacter.rb
Overview
Stores and sets global configuration
This module stores a global instance of Settings and contains methods for initializing the settings instance from various sources.
Defined Under Namespace
Classes: Settings
Class Method Summary collapse
-
.config ⇒ RFacter::Config::Settings
Return global configuration.
-
.configure_from_argv!(argv) ⇒ Array<string>
Set global configuration from an argument vector.
-
.parse_argv(argv, settings = nil) ⇒ Array<Array<String>, RFacter::Config::Settings>
Configure a settings instance by parsing an argument vector.
Class Method Details
.config ⇒ RFacter::Config::Settings
Return global configuration
22 23 24 |
# File 'lib/rfacter/config.rb', line 22 def self.config @settings ||= RFacter::Config::Settings.new end |
.configure_from_argv!(argv) ⇒ Array<string>
Set global configuration from an argument vector
This method calls parse_argv and uses the results to update the settings instance returned by config.
36 37 38 39 40 |
# File 'lib/rfacter/config.rb', line 36 def self.configure_from_argv!(argv) args, _ = parse_argv(argv, self.config) args end |
.parse_argv(argv, settings = nil) ⇒ Array<Array<String>, RFacter::Config::Settings>
Configure a settings instance by parsing an argument vector
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rfacter/config.rb', line 54 def self.parse_argv(argv, settings = nil) settings ||= RFacter::Config::Settings.new parser = OptionParser.new args = argv.dup parser.separator("\nOptions\n=======") parser.on('--version', 'Print version number and exit.') do puts RFacter::VERSION exit 0 end parser.on('-h', '--help', 'Print this help message.') do puts parser.help exit 0 end parser.on('-v', '--verbose', 'Raise log level to INFO.') do settings.logger.level = Logger::INFO end parser.on('-d', '--debug', 'Raise log level to DEBUG.') do settings.logger.level = Logger::DEBUG end parser.on('--profile', 'Profile fact resolution times.') do settings.profile = true end parser.on('-n', '--node', '=MANDATORY', URI, 'Add a node by URI.') do |uri| node = RFacter::Node.new(uri) settings.nodes[node.hostname] = node end parser.parse!(args) [args, settings] end |