lib/synvert/cli.rb in synvert-1.1.2 vs lib/synvert/cli.rb in synvert-1.1.3
- old
+ new
@@ -41,19 +41,16 @@
when 'sync'
sync_snippets
when 'generate'
generate_snippet
when 'execute'
- read_rewriters
execute_snippet(@options[:execute_command])
when 'test'
- read_rewriters
- rewriter = eval_snippet(@options[:snippet_name])
+ rewriter = Synvert::Core::Utils.eval_snippet(@options[:snippet_name])
test_snippet(rewriter)
when 'run'
- read_rewriters
- rewriter = eval_snippet(@options[:snippet_name])
+ rewriter = Synvert::Core::Utils.eval_snippet(@options[:snippet_name])
run_snippet(rewriter)
else
# nothing to do
end
true
@@ -231,42 +228,27 @@
puts "synvert-core is updated, installing synvert-core #{core_version}"
system('gem install synvert-core')
end
end
- # eval snippet by name
- # it can eval by explicit snippet name,
- # or from local path or http url.
- def eval_snippet(snippet_name)
- if /^http/.match?(snippet_name)
- uri = URI.parse(Utils.format_url(snippet_name))
- eval(uri.open.read)
- elsif File.exists?(snippet_name)
- eval(File.read(snippet_name))
- else
- require(File.join(default_snippets_home, 'lib', "#{snippet_name}.rb"))
- group, name = snippet_name.split('/')
- Core::Rewriter.fetch(group, name)
- end
- end
-
# eval snippet name by user input
def eval_snippet_name_by_input(input)
eval(input)
end
# run a snippet
def run_snippet(rewriter)
- rewriter.process
if plain_output?
puts "===== #{rewriter.group}/#{rewriter.name} started ====="
+ rewriter.process
rewriter.warnings.each do |warning|
puts '[Warn] ' + warning.message
end
puts rewriter.todo if rewriter.todo
puts "===== #{rewriter.group}/#{rewriter.name} done ====="
elsif json_output?
+ 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)),
todo: rewriter.todo
}
@@ -275,12 +257,9 @@
end
# test a snippet
def test_snippet(rewriter)
results = rewriter.test
- rewriter.sub_snippets.each do |sub_snippet|
- results += sub_snippet.test_results
- end
puts JSON.generate(results)
end
# execute snippet
def execute_snippet(execute_command)