Module: WarningShot::Config
- Defined in:
- lib/warningshot/config.rb
Constant Summary collapse
- PARSER =
OptionParser.new
- DEFAULTS =
{ :pload => [], :oload => [], :environment => 'development', :resolve => false, :config_paths => ['.' / 'config' / 'warningshot', '~' / '.warningshot'], :application => '.', :log_path => '.' / 'log' / 'warningshot.log', :log_level => :info, :growl => false, :verbose => false, :colorize => true, :resolvers => ['~' / '.warningshot' / '*.rb'] }.freeze
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Class Method Summary collapse
-
.cli(*opts, &block) ⇒ Object
Add command line flags to tail of CLI shortcut to WarningSHot::Config::PARSER.on_tail.
-
.cli_options ⇒ Hash
access to a hash for command line options use for Plugin to extend interface.
-
.create(config = {}) ⇒ Object
Initialize a new WarningShot config.
- .parse_args(argv = ARGV) ⇒ Object
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
24 25 26 |
# File 'lib/warningshot/config.rb', line 24 def configuration @configuration end |
Class Method Details
.cli(*opts, &block) ⇒ Object
Add command line flags to tail of CLI shortcut to WarningSHot::Config::PARSER.on_tail
54 55 56 |
# File 'lib/warningshot/config.rb', line 54 def cli(*opts,&block) PARSER.on_tail(*opts,&block) end |
.cli_options ⇒ Hash
access to a hash for command line options use for Plugin to extend interface
61 62 63 64 |
# File 'lib/warningshot/config.rb', line 61 def @@cli_options ||={} @@cli_options end |
.create(config = {}) ⇒ Object
Initialize a new WarningShot config
88 89 90 91 92 93 94 95 96 |
# File 'lib/warningshot/config.rb', line 88 def create(config={}) opt_config = config if block_given? blk_config = {} yield(blk_config) opt_config = opt_config.merge(blk_config) end WarningShot::Config::DEFAULTS.clone.merge(opt_config) end |
.parse_args(argv = ARGV) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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 248 249 250 |
# File 'lib/warningshot/config.rb', line 98 def parse_args(argv = ARGV) @@cli_options = {} @@cli_options[:environment] = ENV["WARNING_SHOT_ENV"] if ENV["WARNING_SHOT_ENV"] WarningShot::Config::PARSER. = WarningShot.header WarningShot::Config::PARSER. += "\n" WarningShot::Config::PARSER. += "Dependency Resolution Framework\n\n" WarningShot::Config::PARSER. += "Usage: warningshot [options]" WarningShot::Config::PARSER.separator "Standard Flags".center(80,'-') WarningShot::Config::PARSER.on("-e=STRING", "--environment=STRING", String, "Environment to test in","Default: #{DEFAULTS[:environment]}") do |env| @@cli_options[:environment] = env end WarningShot::Config::PARSER.on("--resolve","Resolve missing dependencies (probably need sudo)") do |resolve| @@cli_options[:resolve] = resolve end WarningShot::Config::PARSER.on("-a=PATH","--app=PATH", String, "Path to application", "Default: #{DEFAULTS[:application]}") do |app| @@cli_options[:application] = app end WarningShot::Config::PARSER.on("-c=PATH","--configs=PATH", String,"Path to config directories (':' seperated)","Default: #{DEFAULTS[:config_paths].join(':')}") do |config| @@cli_options[:config_paths] = config.split(':') end WarningShot::Config::PARSER.separator "Resolver Loading Flags".center(80,'-') WarningShot::Config::PARSER.on("-r=PATH","--resolvers=PATH", String,"Globs to add'l resolvers (':' seperated)","Default: #{DEFAULTS[:resolvers].join(':')}") do |config| @@cli_options[:resolvers] = config.split(':') end WarningShot::Config::PARSER.on("--oload=LIST", String, "Only load specified resolvers (Command seperated)") do |oload| @@cli_options[:oload] = oload.split(',') WarningShot.only_load *@@cli_options[:oload] end WarningShot::Config::PARSER.on("--pload=LIST", String, "Load specified resolvers only, setting sequential priority (Command seperated)") do |pload| @@cli_options[:pload] = pload.split(',') WarningShot.only_load *@@cli_options[:pload] end WarningShot::Config::PARSER.separator "Output Flags".center(80,'-') WarningShot::Config::PARSER.on("-l=LOG","--log=LOG", String, "Path to log file", "Default: #{DEFAULTS[:log_path]}") do |log_path| @@cli_options[:log_path] = log_path end WarningShot::Config::PARSER.on("--loglevel=LEVEL",[:debug, :info, :warn, :error, :fatal], "Default: #{DEFAULTS[:log_level]}") do |log_level| @@cli_options[:log_level] = log_level end WarningShot::Config::PARSER.on("-g", "--growl", "Output results via growl (Requires growlnotify)") do |growl| @@cli_options[:growl] = growl end WarningShot::Config::PARSER.on("-p", "--[no-]prettycolors", "Colorize output") do |colorize| @@cli_options[:colorize] = colorize end WarningShot::Config::PARSER.on("-v", "--verbose", "Output verbose information") do |verbose| @@cli_options[:verbose] = verbose end WarningShot::Config::PARSER.on("--very-verbose", "Outputs debugging information, same as --loglevel=DEBUG") do |verbose| @@cli_options[:verbose] = true @@cli_options[:log_level] = :debug end WarningShot::Config::PARSER.separator "Prestaging Flags".center(80,'-') WarningShot::Config::PARSER.on("--build-deps", "Installs gems that WarningShot resolvers depend on into standard RubyGems path (probably need sudo)") do |deps| build_deps_config = WarningShot::Config.create WarningShot.load_addl_resolvers build_deps_config[:resolvers] warningshot_gem_recipe = [] Resolver.descendants(false).each do |klass| klass.depends_on[:gem].each{ |gem_dep| warningshot_gem_recipe.push(gem_dep) } end gem_resolver = WarningShot::GemResolver.new build_deps_config, *warningshot_gem_recipe gem_resolver.test! if gem_resolver.failed.length == 0 puts 'WarningShot is A-OK!!!' else gem_resolver.resolve! gem_resolver.resolved.each{|res_gem| puts "[SUCCESS]\t\t#{res_gem.name}" } gem_resolver.unresolved.each{|unres_gem| puts "[FAILURE]\t\t#{unres_gem.name}" } end exit end WarningShot::Config::PARSER.on("--list-deps", "List all core libs and gems that each resolver is dependent on") do |deps| puts WarningShot.header puts "Resolvers' dependencies:" Resolver.descendants(false).each do |klass| puts "\n#{klass}" puts " Core Lib Dependencies:" klass.depends_on[:core].each do |core| puts " [#{core[:installed] ? 'INSTALLED' : 'MISSING'}]\t\t#{core[:name]}" end puts " Gem Dependencies:" klass.depends_on[:gem].each do |gem| puts " [#{gem[:installed] ? 'INSTALLED' : 'MISSING'}]\t\t#{gem[:name]}" end end exit end WarningShot::Config::PARSER.separator "Help, Info, & Etc. Flags".center(80,'-') WarningShot::Config::PARSER.on("-t[PATH]","--templates[PATH]", String, "Generate template files", "Default: .") do |template_path| template_path = @@cli_options[:config_paths].first if template_path.nil? || template_path.empty? WarningShot::TemplateGenerator.create(template_path) exit end WarningShot::Config::PARSER.on("--version", "Show version"){ WarningShot::Config::PARSER.parse!(argv) conf = WarningShot::Config.create(@@cli_options) WarningShot.load_app(conf[:application]) WarningShot.load_addl_resolvers(conf[:resolvers]) puts WarningShot.header puts "Installed resolvers:" Resolver.descendants(false).each { |klass| puts "\n#{klass}" puts " Tests: #{klass.tests.length}, Resolutions: #{klass.resolutions.length} [#{klass.resolutions.empty? ? 'irresolvable' : 'resolvable'}]" puts " #{klass.description}" } exit } WarningShot::Config::PARSER.on("-h", "--help","Show this help message") { puts WarningShot::Config::PARSER; exit } WarningShot::Config::PARSER.on("--debugger","Enable debugging") do begin require "ruby-debug" Debugger.start Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings) puts "Debugger enabled" rescue LoadError => ex puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'" exit end end WarningShot::Config::PARSER.separator "Resolver Specific Flags".center(80,'-') WarningShot::Config::PARSER.parse!(argv) @curr_config = @@cli_options.clone @@cli_options = {} return WarningShot::Config.create(@curr_config) rescue OptionParser::InvalidOption, OptionParser::InvalidArgument,OptionParser::NeedlessArgument => op puts op puts WarningShot::Config::PARSER; end |