lib/fontcustom/options.rb in fontcustom-1.3.0.beta4 vs lib/fontcustom/options.rb in fontcustom-1.3.0
- old
+ new
@@ -1,13 +1,12 @@
require "yaml"
+require "pp"
module Fontcustom
class Options
include Utility
- attr_accessor :options
-
def initialize(cli_options = {})
@manifest = cli_options[:manifest]
@cli_options = symbolize_hash(cli_options)
parse_options
end
@@ -22,10 +21,11 @@
clean_font_name
clean_css_selector
set_input_paths
set_output_paths
check_template_paths
+ print_debug if @options[:debug]
end
# We give Thor fake defaults to generate more useful help messages.
# Here, we delete any CLI options that match those examples.
# TODO There's *got* a be a cleaner way to customize Thor help messages.
@@ -58,15 +58,15 @@
end
def load_config
@config_options = {}
if @cli_options[:config]
- say_message :debug, "Using settings from `#{@cli_options[:config]}`." if @cli_options[:debug]
begin
config = YAML.load File.open(@cli_options[:config])
if config # empty YAML returns false
@config_options = symbolize_hash(config)
+ say_message :debug, "Using settings from `#{@cli_options[:config]}`." if @cli_options[:debug] || @config_options[:debug]
else
say_message :warn, "`#{@cli_options[:config]}` was empty. Using defaults."
end
rescue Exception => e
raise Fontcustom::Error, "Error parsing `#{@cli_options[:config]}`:\n#{e.message}"
@@ -107,11 +107,16 @@
check_input @options[:input][:templates]
else
@options[:input][:templates] = @options[:input][:vectors]
end
else
- input = @options[:input] ? @options[:input] : "."
+ if @options[:input]
+ input = @options[:input]
+ else
+ input = "."
+ say_message :warn, "No input directory given. Using present working directory."
+ end
check_input input
@options[:input] = { :vectors => input, :templates => input }
end
if Dir[File.join(@options[:input][:vectors], "*.svg")].empty?
@@ -161,11 +166,11 @@
@options[:templates].each do |template|
next if %w|preview css scss scss-rails|.include? template
path = File.expand_path File.join(@options[:input][:templates], template) unless template[0] == "/"
unless File.exists? path
raise Fontcustom::Error,
- "Custom template `#{template}` doesn't exist. Check your options."
+ "Custom template `#{template}` wasn't found in `#{@options[:input][:templates]}/`. Check your options."
end
end
end
def check_input(dir)
@@ -174,8 +179,14 @@
"Input `#{dir}` doesn't exist. Check your options."
elsif ! File.directory? dir
raise Fontcustom::Error,
"Input `#{dir}` isn't a directory. Check your options."
end
+ end
+
+ def print_debug
+ message = line_break(16)
+ message << @options.pretty_inspect.split("\n ").join(line_break(16))
+ say_message :debug, "Using options:#{message}"
end
end
end