Class: AptControl::CLI::Root
- Inherits:
-
Object
- Object
- AptControl::CLI::Root
- Extended by:
- AptControl::ConfigDSL
- Defined in:
- lib/apt_control/cli.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILE_LOCATION =
'/etc/apt_control/config.yaml'
Instance Method Summary collapse
- #apt_site ⇒ Object
- #build_archive ⇒ Object
-
#build_config ⇒ Object
Read yaml file if one exists, then apply overrides from the command line.
- #config ⇒ Object
- #control_file ⇒ Object
- #logger ⇒ Object
- #notifier ⇒ Object
- #notify(message) ⇒ Object
- #validate_config! ⇒ Object
Methods included from AptControl::ConfigDSL
Instance Method Details
#apt_site ⇒ Object
144 145 146 |
# File 'lib/apt_control/cli.rb', line 144 def apt_site @apt_site ||= AptSite.new(config[:apt_site_dir], logger) end |
#build_archive ⇒ Object
152 153 154 |
# File 'lib/apt_control/cli.rb', line 152 def build_archive @build_archive ||= BuildArchive.new(config[:build_archive_dir], logger) end |
#build_config ⇒ Object
Read yaml file if one exists, then apply overrides from the command line
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/apt_control/cli.rb', line 105 def build_config file = [[:config_file], DEFAULT_CONFIG_FILE_LOCATION]. compact.find {|f| File.exists?(f) } hash = if file YAML.load_file(file).each do |key, value| stderr.puts("Warn: Unknown key in config file: #{key}") unless self.class.configs.find {|opt| opt.first.to_s == key.to_s } end else {} end [:config_option].map {|str| str.split('=') }. inject(hash) {|m, (k,v)| m.merge(k.to_sym => v) } end |
#config ⇒ Object
98 99 100 |
# File 'lib/apt_control/cli.rb', line 98 def config @config ||= build_config end |
#control_file ⇒ Object
148 149 150 |
# File 'lib/apt_control/cli.rb', line 148 def control_file @control_file ||= ControlFile.new(config[:control_file], logger) end |
#logger ⇒ Object
138 139 140 141 142 |
# File 'lib/apt_control/cli.rb', line 138 def logger @logger ||= Logger.new(config[:log_file] || STDOUT).tap do |logger| logger.level = Logger::DEBUG end end |
#notifier ⇒ Object
156 157 158 159 |
# File 'lib/apt_control/cli.rb', line 156 def notifier @notify ||= Notify::Jabber.new(:jid => config[:jabber_id], :logger => logger, :password => config[:jabber_password], :room_jid => config[:jabber_chatroom_id]) end |
#notify(message) ⇒ Object
161 162 163 164 165 |
# File 'lib/apt_control/cli.rb', line 161 def notify() logger.info("notify: #{}") return unless config[:jabber_enabled] notifier.() end |
#validate_config! ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/apt_control/cli.rb', line 123 def validate_config! self.class.configs.each do |key, desc, | if [:required] config[key] or raise Climate::ExitException, "Error: No config supplied for #{key}" end end if config[:jabber_enabled] self.class.configs.each do |key, desc, | next unless key.to_s['jabber_'] config[key] or raise Climate::ExitException, "Error: you must supply all jabber options if jabber is enabled" end end end |