lib/scss_beautifier/cli.rb in scss_beautifier-0.1.8 vs lib/scss_beautifier/cli.rb in scss_beautifier-0.1.10

- old
+ new

@@ -2,19 +2,27 @@ class CLI DEFAULT = File.realpath(File.join(File.dirname(__FILE__), "..", "..", "data", "default_config.yml")).freeze # Takes an array of arguments # Returns exit code def run(args) - contents = File.read(ARGV.first) + options = Options.new.parse(args) + + contents = File.read(args.first) engine = Sass::Engine.new(contents, cache: false, syntax: :scss) tree = engine.to_tree - Config.new(DEFAULT).formatters.each do |formatter| + config = Config.new(options[:config] || DEFAULT) + + config.formatters.each do |formatter| formatter.visit(tree) end - puts SCSSBeautifier::Convert.visit(tree, {}, :scss) - + output = SCSSBeautifier::Convert.visit(tree, {indent: config.tab_style}, :scss) + if options[:in_place] + File.write(args.first, output) + else + puts output + end end end -end \ No newline at end of file +end