lib/synvert/cli.rb in synvert-1.4.1 vs lib/synvert/cli.rb in synvert-1.4.2

- old
+ new

@@ -1,9 +1,8 @@ # frozen_string_literal: true require 'optparse' -require 'json' require 'fileutils' module Synvert # Synvert command line interface. class CLI @@ -97,15 +96,19 @@ end opts.on '--execute EXECUTE_COMMAND', 'execute snippet' do |execute_command| @options[:command] = 'execute' @options[:execute_command] = execute_command end - opts.on '-r', '--run SNIPPET_NAME', 'run a snippet with snippet name, e.g. ruby/new_hash_syntax, or remote url, or local file path' do |snippet_name| + opts.on '-r', + '--run SNIPPET_NAME', + 'run a snippet with snippet name, e.g. ruby/new_hash_syntax, or remote url, or local file path' do |snippet_name| @options[:command] = 'run' @options[:snippet_name] = snippet_name end - opts.on '-t', '--test SNIPPET_NAME', 'test a snippet with snippet name, e.g. ruby/new_hash_syntax, or remote url, or local file path' do |snippet_name| + opts.on '-t', + '--test SNIPPET_NAME', + 'test a snippet with snippet name, e.g. ruby/new_hash_syntax, or remote url, or local file path' do |snippet_name| @options[:command] = 'test' @options[:snippet_name] = snippet_name end opts.on '--show-run-process', 'show processing files when running a snippet' do Core::Configuration.show_run_process = true @@ -119,14 +122,15 @@ @options[:skip_paths] = file_patterns end opts.on '-f', '--format FORMAT', 'output format' do |format| @options[:format] = format end - opts.on '--number-of-workers NUMBER_OF_WORKERS', 'set the number of workers, if it is greater than 1, it tests snippet in parallel' do |number_of_workers| + opts.on '--number-of-workers NUMBER_OF_WORKERS', + 'set the number of workers, if it is greater than 1, it tests snippet in parallel' do |number_of_workers| Core::Configuration.number_of_workers = number_of_workers.to_i end - opts.on '--double-quote', 'prefer double quote, it uses single quote by default' do |double_quote| + opts.on '--double-quote', 'prefer double quote, it uses single quote by default' do |_double_quote| Core::Configuration.single_quote = false end opts.on '--tab-width TAB_WIDTH', 'prefer tab width, it uses 2 by default' do |tab_width| Core::Configuration.tab_width = tab_width.to_i end @@ -179,11 +183,11 @@ item[:gem_spec] = { name: rewriter.gem_spec.name, version: rewriter.gem_spec.version } if rewriter.gem_spec output << item end end - puts JSON.generate(output) + puts output.to_json end end # Open one rewriter. def open_rewriter @@ -250,26 +254,26 @@ rewriter.process output = { affected_files: rewriter.affected_files.union(rewriter.sub_snippets.sum(Set.new, &:affected_files)).to_a, warnings: rewriter.warnings.union(rewriter.sub_snippets.sum([], &:warnings)) } - puts JSON.generate(output) + puts output.to_json end rescue StandardError => e if plain_output? puts "Error: #{e.message}" else - puts JSON.generate(error: e.message) + puts({ error: e.message }.to_json) end raise end # test a snippet def test_snippet(rewriter) results = rewriter.test - puts JSON.generate(results) + puts results.to_json rescue StandardError => e - puts JSON.generate(error: e.message) + puts({ error: e.message }.to_json) raise end # execute snippet def execute_snippet(execute_command)