Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up options parser, implemented block configuration

  • Loading branch information...
commit 50002c75b0d8ca0146c9ea4b8514b2ba57370f94 1 parent e34d80f
@caseyohara caseyohara authored
View
22 bin/coyote
@@ -9,21 +9,15 @@ require 'coyote'
options = {}
OptionParser.new do |opts|
- opts.on("-c", "--compressed", "Compress") do |option|
- options[:compress] = option
+ Coyote::options.each do |name|
+ opts.on("-#{name[0]}", "--#{name}", "#{name.capitalize}") { |o| options[name.to_sym] = o }
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!
+input, output = ARGV[0].split(':', 2)
-input_path, output_path = ARGV[0].split(':', 2)
-
-Coyote::run(input_path, output_path, options)
+coyote :build do |config|
+ config.input = input
+ config.output = output
+ config.options = options
+end
View
12 lib/coyote.rb
@@ -1,3 +1,4 @@
+require 'coyote/configuration'
require 'coyote/bundle'
require 'coyote/fs_listener'
require 'coyote/notifications'
@@ -7,7 +8,7 @@
module Coyote
VERSION = '1.0.0.beta1'
-
+
def self.run(input_path, output_path, options = {})
@@input_path = input_path
@@output_path = output_path
@@ -17,6 +18,9 @@ def self.run(input_path, output_path, options = {})
watch bundle if @@options[:watch]
end
+ def self.options
+ ['compress', 'watch', 'quiet']
+ end
def self.build(bundle)
notify bundle.manifest unless @@options[:quiet]
@@ -42,8 +46,4 @@ def self.watch(bundle)
notify "Watching for changes to your bundle. CTRL+C to stop."
listener.start
end
-
-end
-
-
-
+end
View
31 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
View
2  lib/coyote/notifications.rb
@@ -13,7 +13,7 @@ def notify(msg, type = :message)
case type
when :success ; print msg.green
when :warning ; print msg.yellow
- when :failure ; print msg.white.on_red.blink
+ when :failure ; print msg.red
else ; print msg.white
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.