lib/kicker/options.rb in kicker-2.1.0 vs lib/kicker/options.rb in kicker-2.2.0

- old
+ new

@@ -1,49 +1,74 @@ require 'optparse' class Kicker - DONT_SHOW_RECIPES = %w{ could_not_handle_file execute_cli_command dot_kick } - - def self.recipes_for_display - [RECIPES_DIR, USER_RECIPES_DIR].map do |dir| - Dir.glob("#{dir}/*.rb").map { |f| File.basename(f, '.rb') } - end.flatten - DONT_SHOW_RECIPES - end - - def self.option_parser - @option_parser ||= OptionParser.new do |opt| - opt.banner = "Usage: #{$0} [options] [paths to watch]" + class << self + attr_accessor :latency, :paths, :silent, :quiet + + def silent? + @silent end + + def quiet? + @quiet + end end - OPTION_PARSER_CALLBACK = lambda do |options| - option_parser.on('--[no-]growl', 'Whether or not to use Growl. Default is to use growl.') do |growl| - options[:growl] = growl - end + self.latency = 1 + self.paths = %w{ . } + self.silent = false + self.quiet = false + + module Options #:nodoc: + DONT_SHOW_RECIPES = %w{ could_not_handle_file execute_cli_command dot_kick } - option_parser.on('--growl-command [COMMAND]', 'The command to execute when the Growl succeeded message is clicked.') do |command| - options[:growl_command] = command + def self.recipes_for_display + Kicker::Recipes.recipe_files.map { |f| File.basename(f, '.rb') } - DONT_SHOW_RECIPES end - option_parser.on('-l', '--latency [FLOAT]', "The time to collect file change events before acting on them. Defaults to 1 second.") do |latency| - options[:latency] = Float(latency) + def self.parser + @parser ||= OptionParser.new do |opt| + opt.banner = "Usage: #{$0} [options] [paths to watch]" + opt.separator " " + opt.separator " Available recipes: #{recipes_for_display.join(", ")}." + opt.separator " " + + opt.on('-s', '--silent', 'Keep output to a minimum.') do |silent| + Kicker.silent = true + end + + opt.on('-q', '--quiet', "Quiet output. Don't print timestamps when logging.") do |quiet| + Kicker.silent = Kicker.quiet = true + end + + opt.on('--[no-]growl', 'Whether or not to use Growl. Default is to use growl.') do |growl| + Kicker::Growl.use = growl + end + + opt.on('--growl-command [COMMAND]', 'The command to execute when the Growl succeeded message is clicked.') do |command| + Kicker::Growl.command = command + end + + opt.on('-l', '--latency [FLOAT]', "The time to collect file change events before acting on them. Defaults to #{Kicker.latency} second.") do |latency| + Kicker.latency = Float(latency) + end + + opt.on('-r', '--recipe [NAME]', 'A named recipe to load.') do |name| + recipe(name) + end + end end - option_parser.on('-r', '--recipe [NAME]', 'A named recipe to load.') do |recipe| - (options[:recipes] ||= []) << recipe + def self.parse(argv) + parser.parse!(argv) + Kicker.paths = argv unless argv.empty? end - - option_parser.separator " " - option_parser.separator " Available recipes:" - Kicker.recipes_for_display.each { |recipe| option_parser.separator " - #{recipe}" } - - option_parser end - - def self.parse_options(argv) - argv = argv.dup - options = { :growl => true } - OPTION_PARSER_CALLBACK.call(options).parse!(argv) - options[:paths] = argv unless argv.empty? - options +end + +module Kernel + # Returns the global OptionParser instance that recipes can use to add + # options. + def options + Kicker::Options.parser end end \ No newline at end of file