lib/style_stats/cli.rb in style_stats-0.1.0 vs lib/style_stats/cli.rb in style_stats-0.2.0

- old
+ new

@@ -1,10 +1,15 @@ class StyleStats class CLI class << self def run(files, option) @options = option + StyleStats.configure do |config| + config.options[:requestOptions][:headers]['User-Agent'] = user_agent + config.options.merge!(configuration) + end + stylestats = StyleStats.new(files, options) stylestats.render rescue StyleStats::RequestError puts '[ERROR] getaddrinfo ENOTFOUND' rescue StyleStats::ContentError @@ -14,12 +19,11 @@ end private def options { - format: @options[:format], - user_agent: user_agent + format: @options[:format] } end def user_agent case @options[:user_agent] @@ -28,9 +32,21 @@ when 'android' 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 5 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.99 Mobile Safari/537.36' else @options[:user_agent] end + end + + def configuration + config = case File.extname(@options[:config].to_s) + when '.yml', '.yaml' + YAML.load_file(@options[:config]) + when '.json' + json = File.read(@options[:config]) + JSON.parse(json) + else + {} + end end end end end