module SCSSBeautifier class CLI def run(args) options = Options.new.parse(args) generate_configuration and return if options[:generate_config] contents = args.first.nil? ? $stdin.read : File.read(args.first) engine = Sass::Engine.new(contents, cache: false, syntax: :scss) tree = engine.to_tree config = Config.new(options[:config]) config.formatters.each do |formatter| formatter.send(:visit, tree) end output = SCSSBeautifier::Convert.visit(tree, config.options, :scss) if options[:in_place] File.write(args.first, output) else puts output end end private def generate_configuration File.write(".scss-beautifier", File.read(Config::DEFAULT)) end end end