synvert 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25902dede2581c67bde78c934df502178f3dc715
4
- data.tar.gz: bf27812b8d38bad69e16b39690b9e98d5fc03aa8
3
+ metadata.gz: ad8467c3b26e89499b67e13b5c4441a5b9d20a69
4
+ data.tar.gz: 701ad231cea1d52fc69827ced8610bcb7a07ebce
5
5
  SHA512:
6
- metadata.gz: 1a6ec80231ba84c4f45fb15275c7a6d48e1fb67894f7f8ddc4e7f08ead32773c5da229d4e97591f7170fa15740d9c5d03195d8e2e3d16f1d212185fc678041f8
7
- data.tar.gz: 932dfcb6832a8bcba9d5c1fc56e71875d4c057b859887f42edbca8fe690b4a1602e5ed23372421c199a425c5727a2d2aa5e2617f3694d78ec092b4741ae3b2d2
6
+ metadata.gz: ec940d0d793d9df5183fd06a670ecd545b229db7cd69cd698120172d4d304cd5a321edb71b9693bcb021596571b8633377751898972c0fc27f65b652a50e728d
7
+ data.tar.gz: 1a3c11744001240a5545aeb77c7ad4cee4d1e82c3c6913b2d5dcb8dd256816743d36f3ae30139b6e2515d8e7c8f65ad87a4147d4863a6f4a464f3916ca5f81a0
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.5.0
4
+
5
+ * rewrite cli for rewriter group
6
+
3
7
  ## 0.4.2
4
8
 
5
9
  * Tell user to update synvert-core if necessary after syncing snippets.
@@ -34,7 +34,8 @@ module Synvert
34
34
  else
35
35
  @options[:snippet_names].each do |snippet_name|
36
36
  puts "===== #{snippet_name} started ====="
37
- rewriter = Core::Rewriter.call snippet_name
37
+ group, name = snippet_name.split('/')
38
+ rewriter = Core::Rewriter.call group, name
38
39
  rewriter.warnings.each do |warning|
39
40
  puts "[Warn] " + warning.message
40
41
  end
@@ -50,10 +51,6 @@ module Synvert
50
51
  puts "file #{e.diagnostic.location.source_buffer.name}"
51
52
  puts "line #{e.diagnostic.location.line}"
52
53
  false
53
- rescue Exception => e
54
- print "Error: "
55
- p e
56
- false
57
54
  end
58
55
 
59
56
  private
@@ -75,14 +72,14 @@ module Synvert
75
72
  opts.on '--skip FILE_PATTERNS', 'skip specified files or directories, separated by comma, e.g. app/models/post.rb,vendor/plugins/**/*.rb' do |file_patterns|
76
73
  @options[:skip_file_patterns] = file_patterns.split(',')
77
74
  end
78
- opts.on '-s', '--show SNIPPET_NAME', 'show specified snippet description' do |snippet_name|
75
+ opts.on '-s', '--show SNIPPET_NAME', 'show specified snippet description, SNIPPET_NAME is combined by group and name, e.g. ruby/new_hash_syntax' do |snippet_name|
79
76
  @options[:command] = 'show'
80
77
  @options[:snippet_name] = snippet_name
81
78
  end
82
79
  opts.on '--sync', 'sync snippets' do
83
80
  @options[:command] = 'sync'
84
81
  end
85
- opts.on '-r', '--run SNIPPET_NAMES', 'run specified snippets' do |snippet_names|
82
+ opts.on '-r', '--run SNIPPET_NAMES', 'run specified snippets, each SNIPPET_NAME is combined by group and name, e.g. ruby/new_hash_syntax,ruby/new_lambda_syntax' do |snippet_names|
86
83
  @options[:snippet_names] = snippet_names.split(',').map(&:strip)
87
84
  end
88
85
  opts.on '-v', '--version', 'show this version' do
@@ -114,6 +111,9 @@ module Synvert
114
111
  eval(File.read(snippet_path))
115
112
  end
116
113
  end
114
+ rescue
115
+ FileUtils.rm_rf default_snippets_path
116
+ retry
117
117
  end
118
118
 
119
119
  # List and print all available rewriters.
@@ -121,8 +121,11 @@ module Synvert
121
121
  if Core::Rewriter.availables.empty?
122
122
  puts "There is no snippet under ~/.synvert, please run `synvert --sync` to fetch snippets."
123
123
  else
124
- Core::Rewriter.availables.each do |rewriter|
125
- print rewriter.name.to_s + " "
124
+ Core::Rewriter.availables.each do |group, rewriters|
125
+ puts group
126
+ rewriters.each do |name, rewriter|
127
+ puts " " + name
128
+ end
126
129
  end
127
130
  puts
128
131
  end
@@ -130,9 +133,17 @@ module Synvert
130
133
 
131
134
  # Query and print available rewriters.
132
135
  def query_available_rewriters
133
- Core::Rewriter.availables.each do |rewriter|
134
- if rewriter.name.include? @options[:query]
135
- print rewriter.name + " "
136
+ Core::Rewriter.availables.each do |group, rewriters|
137
+ if group.include? @options[:query]
138
+ puts group
139
+ rewriters.each do |name, rewriter|
140
+ puts " " + name
141
+ end
142
+ elsif rewriters.keys.any? { |name| name.include? @options[:query] }
143
+ puts group
144
+ rewriters.each do |name, rewriter|
145
+ puts " " + name if name.include?(@options[:query])
146
+ end
136
147
  end
137
148
  end
138
149
  puts
@@ -140,7 +151,8 @@ module Synvert
140
151
 
141
152
  # Show and print one rewriter.
142
153
  def show_rewriter
143
- rewriter = Core::Rewriter.fetch(@options[:snippet_name])
154
+ group, name = @options[:snippet_name].split('/')
155
+ rewriter = Core::Rewriter.fetch(group, name)
144
156
  if rewriter
145
157
  rewriter.process_with_sandbox
146
158
  puts rewriter.description
@@ -10,9 +10,9 @@ module Synvert
10
10
  snippets_path = Core::Configuration.instance.get :default_snippets_path
11
11
  if File.exist?(snippets_path)
12
12
  FileUtils.cd snippets_path
13
- `git pull --rebase --quiet`
13
+ system("git pull --rebase")
14
14
  else
15
- `git clone https://github.com/xinminlabs/synvert-snippets.git #{snippets_path} --quiet`
15
+ system("git clone https://github.com/xinminlabs/synvert-snippets.git #{snippets_path}")
16
16
  end
17
17
  end
18
18
 
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Synvert
4
- VERSION = "0.4.2"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -8,14 +8,14 @@ module Synvert
8
8
  after { FileUtils.rm_rf default_snippets_path }
9
9
 
10
10
  it 'git clones snippets' do
11
+ expect(Snippet).to receive(:system).with("git clone https://github.com/xinminlabs/synvert-snippets.git #{default_snippets_path}")
11
12
  Snippet.sync
12
- expect(File.exist?(default_snippets_path)).to be_truthy
13
13
  end
14
14
 
15
15
  it 'git pull snippets' do
16
+ FileUtils.mkdir default_snippets_path
17
+ expect(Snippet).to receive(:system).with("git pull --rebase")
16
18
  Snippet.sync
17
- Snippet.sync
18
- expect(File.exist?(default_snippets_path)).to be_truthy
19
19
  end
20
20
  end
21
21
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "synvert-core", ">= 0.4.2"
21
+ spec.add_runtime_dependency "synvert-core", ">= 0.5.0"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-15 00:00:00.000000000 Z
11
+ date: 2014-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: synvert-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.2
19
+ version: 0.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.4.2
26
+ version: 0.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement