Skip to content

Commit

Permalink
Cleaned up options parser, implemented block configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyohara committed Feb 14, 2012
1 parent e34d80f commit 50002c7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
22 changes: 8 additions & 14 deletions bin/coyote
Expand Up @@ -9,21 +9,15 @@ require 'coyote'


options = {} options = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.on("-c", "--compressed", "Compress") do |option| Coyote::options.each do |name|
options[:compress] = option opts.on("-#{name[0]}", "--#{name}", "#{name.capitalize}") { |o| options[name.to_sym] = o }
end end
opts.on("-w", "--watch", "Watch") do |option|
options[:watch] = option
end
opts.on("-q", "--quiet", "Quiet") do |option|
options[:quiet] = option
end
opts.on("-v", "--verbose", "Verbose") do |option|
options[:verbose] = option
end
end.parse! end.parse!


input, output = ARGV[0].split(':', 2)


input_path, output_path = ARGV[0].split(':', 2) coyote :build do |config|

config.input = input
Coyote::run(input_path, output_path, options) config.output = output
config.options = options
end
12 changes: 6 additions & 6 deletions lib/coyote.rb
@@ -1,3 +1,4 @@
require 'coyote/configuration'
require 'coyote/bundle' require 'coyote/bundle'
require 'coyote/fs_listener' require 'coyote/fs_listener'
require 'coyote/notifications' require 'coyote/notifications'
Expand All @@ -7,7 +8,7 @@
module Coyote module Coyote


VERSION = '1.0.0.beta1' VERSION = '1.0.0.beta1'

def self.run(input_path, output_path, options = {}) def self.run(input_path, output_path, options = {})
@@input_path = input_path @@input_path = input_path
@@output_path = output_path @@output_path = output_path
Expand All @@ -17,6 +18,9 @@ def self.run(input_path, output_path, options = {})
watch bundle if @@options[:watch] watch bundle if @@options[:watch]
end end


def self.options
['compress', 'watch', 'quiet']
end


def self.build(bundle) def self.build(bundle)
notify bundle.manifest unless @@options[:quiet] notify bundle.manifest unless @@options[:quiet]
Expand All @@ -42,8 +46,4 @@ def self.watch(bundle)
notify "Watching for changes to your bundle. CTRL+C to stop." notify "Watching for changes to your bundle. CTRL+C to stop."
listener.start listener.start
end end

end
end



31 changes: 31 additions & 0 deletions lib/coyote/configuration.rb
@@ -0,0 +1,31 @@
module Coyote
class Configuration
attr_accessor :input, :output, :options

def initialize
@input = ""; @output = ""; @options = {}
end
end
end


def coyote(method, &block)
config = Coyote::Configuration.new
yield config

if config.input.empty?
notify "Coyote: Input filepath must be defined", :failure
exit 0
end

if config.output.empty?
notify "Coyote: Output filepath must be defined", :failure
exit 0
end

if method == :watch
config.options[:watch] = true
end

Coyote::run config.input, config.output, config.options
end
2 changes: 1 addition & 1 deletion lib/coyote/notifications.rb
Expand Up @@ -13,7 +13,7 @@ def notify(msg, type = :message)
case type case type
when :success ; print msg.green when :success ; print msg.green
when :warning ; print msg.yellow when :warning ; print msg.yellow
when :failure ; print msg.white.on_red.blink when :failure ; print msg.red
else ; print msg.white else ; print msg.white
end end
end end
Expand Down

0 comments on commit 50002c7

Please sign in to comment.