lib/synvert/cli.rb in synvert-0.12.1 vs lib/synvert/cli.rb in synvert-0.13.0
- old
+ new
@@ -135,22 +135,22 @@
end
end
# Load all rewriters.
def load_rewriters
- Dir.glob(File.join(default_snippets_path, 'lib/**/*.rb')).each { |file| require file }
+ Dir.glob(File.join(default_snippets_home, 'lib/**/*.rb')).each { |file| require file }
@options[:custom_snippet_paths].each do |snippet_path|
if /^http/.match?(snippet_path)
uri = URI.parse snippet_path
eval(uri.read)
else
require snippet_path
end
end
rescue StandardError
- FileUtils.rm_rf default_snippets_path
+ FileUtils.rm_rf default_snippets_home
retry
end
# List and print all available rewriters.
def list_available_rewriters
@@ -192,11 +192,11 @@
# Open one rewriter.
def open_rewriter
editor = [ENV['SYNVERT_EDITOR'], ENV['EDITOR']].find { |e| !e.nil? && !e.empty? }
return puts 'To open a synvert snippet, set $EDITOR or $SYNVERT_EDITOR' unless editor
- path = File.expand_path(File.join(default_snippets_path, "lib/#{@options[:snippet_name]}.rb"))
+ path = File.expand_path(File.join(default_snippets_home, "lib/#{@options[:snippet_name]}.rb"))
if File.exist? path
system editor, path
else
puts "Can't run #{editor} #{path}"
end
@@ -220,21 +220,21 @@
puts
end
# Show and print one rewriter.
def show_rewriter
- path = File.expand_path(File.join(default_snippets_path, "lib/#{@options[:snippet_name]}.rb"))
+ path = File.expand_path(File.join(default_snippets_home, "lib/#{@options[:snippet_name]}.rb"))
if File.exist?(path)
puts File.read(path)
else
puts "snippet #{@options[:snippet_name]} not found"
end
end
# sync snippets
def sync_snippets
- Snippet.new(default_snippets_path).sync
+ Snippet.new(default_snippets_home).sync
puts 'synvert snippets are synced'
core_version = Snippet.fetch_core_version
if Gem::Version.new(core_version) > Gem::Version.new(Synvert::Core::VERSION)
puts "synvert-core is updated, please install synvert-core #{core_version}"
end
@@ -286,10 +286,10 @@
EOF
File.write("lib/#{group}/#{name}.rb", lib_content)
File.write("spec/#{group}/#{name}_spec.rb", spec_content)
end
- def default_snippets_path
- File.join(ENV['HOME'], '.synvert')
+ def default_snippets_home
+ ENV['SYNVERT_SNIPPETS_HOME'] || File.join(ENV['HOME'], '.synvert')
end
end
end