synvert 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/synvert/cli.rb +58 -43
- data/lib/synvert/version.rb +1 -1
- data/synvert.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5087621370472c9553a89bfe5b75dfed595f07516adba6a421a6b44cffb33e9c
|
4
|
+
data.tar.gz: bd29c43ab204f043121b5ce85e49bdc18b8eff2f3ca707a48833d2b773634243
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3bf4ec96210d9a4dbf1804267809f1e19e9de8147ff3998831428ab3397d23bf38b24519a70850dbd20141b6b0172b636dabaa425c1bf079374e4578f5e36e4
|
7
|
+
data.tar.gz: 6b90bd131751a8a50956cdadc21572e70a938a975b71e7deb97c5f48c04184f55b16b3f1fe5b06d95de746df40da3275ce2a19cb50222cf0ebdfc8a3496317c7
|
data/CHANGELOG.md
CHANGED
data/lib/synvert/cli.rb
CHANGED
@@ -15,7 +15,7 @@ module Synvert
|
|
15
15
|
|
16
16
|
# Initialize a CLI.
|
17
17
|
def initialize
|
18
|
-
@options = { command: 'run', custom_snippet_paths: [],
|
18
|
+
@options = { command: 'run', custom_snippet_paths: [], format: 'plain' }
|
19
19
|
end
|
20
20
|
|
21
21
|
# Run the CLI.
|
@@ -28,9 +28,6 @@ module Synvert
|
|
28
28
|
when 'list'
|
29
29
|
load_rewriters
|
30
30
|
list_available_rewriters
|
31
|
-
when 'list-all'
|
32
|
-
load_rewriters
|
33
|
-
list_all_rewriters_in_json
|
34
31
|
when 'open'
|
35
32
|
open_rewriter
|
36
33
|
when 'query'
|
@@ -46,16 +43,7 @@ module Synvert
|
|
46
43
|
else
|
47
44
|
# run
|
48
45
|
load_rewriters
|
49
|
-
|
50
|
-
puts "===== #{snippet_name} started ====="
|
51
|
-
group, name = snippet_name.split('/')
|
52
|
-
rewriter = Core::Rewriter.call group, name
|
53
|
-
rewriter.warnings.each do |warning|
|
54
|
-
puts '[Warn] ' + warning.message
|
55
|
-
end
|
56
|
-
puts rewriter.todo if rewriter.todo
|
57
|
-
puts "===== #{snippet_name} done ====="
|
58
|
-
end
|
46
|
+
run_snippet
|
59
47
|
end
|
60
48
|
true
|
61
49
|
rescue SystemExit
|
@@ -82,9 +70,6 @@ module Synvert
|
|
82
70
|
'load custom snippets, snippet paths can be local file path or remote http url' do |snippet_paths|
|
83
71
|
@options[:custom_snippet_paths] = snippet_paths.split(',').map(&:strip)
|
84
72
|
end
|
85
|
-
opts.on '--list-all', 'list all available snippets name and description in json format' do
|
86
|
-
@options[:command] = 'list-all'
|
87
|
-
end
|
88
73
|
opts.on '-l', '--list', 'list all available snippets' do
|
89
74
|
@options[:command] = 'list'
|
90
75
|
end
|
@@ -110,14 +95,17 @@ module Synvert
|
|
110
95
|
@options[:command] = 'sync'
|
111
96
|
end
|
112
97
|
opts.on '-r',
|
113
|
-
'--run
|
114
|
-
'run specified
|
115
|
-
@options[:
|
98
|
+
'--run SNIPPET_NAME',
|
99
|
+
'run specified snippet, e.g. ruby/new_hash_syntax' do |snippet_name|
|
100
|
+
@options[:snippet_name] = snippet_name
|
116
101
|
end
|
117
102
|
opts.on '-g', '--generate NEW_SNIPPET_NAME', 'generate a new snippet' do |name|
|
118
103
|
@options[:command] = 'generate'
|
119
104
|
@options[:snippet_name] = name
|
120
105
|
end
|
106
|
+
opts.on '-f', '--format FORMAT', 'output format' do |format|
|
107
|
+
@options[:format] = format
|
108
|
+
end
|
121
109
|
opts.on '-v', '--version', 'show this version' do
|
122
110
|
puts "#{VERSION} (with synvert-core #{Core::VERSION} and parser #{Parser::VERSION})"
|
123
111
|
exit
|
@@ -156,7 +144,10 @@ module Synvert
|
|
156
144
|
def list_available_rewriters
|
157
145
|
if Core::Rewriter.availables.empty?
|
158
146
|
puts 'There is no snippet under ~/.synvert, please run `synvert --sync` to fetch snippets.'
|
159
|
-
|
147
|
+
return
|
148
|
+
end
|
149
|
+
|
150
|
+
if plain_output?
|
160
151
|
Core::Rewriter.availables.each do |group, rewriters|
|
161
152
|
puts group
|
162
153
|
rewriters.each do |name, _rewriter|
|
@@ -164,29 +155,22 @@ module Synvert
|
|
164
155
|
end
|
165
156
|
end
|
166
157
|
puts
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
rewriter.process_with_sandbox
|
180
|
-
output << {
|
181
|
-
group: group,
|
182
|
-
name: name,
|
183
|
-
description: rewriter.description,
|
184
|
-
sub_snippets: rewriter.sub_snippets.map(&:name)
|
185
|
-
}
|
158
|
+
elsif json_output?
|
159
|
+
output = []
|
160
|
+
Core::Rewriter.availables.each do |group, rewriters|
|
161
|
+
rewriters.each do |name, rewriter|
|
162
|
+
rewriter.process_with_sandbox
|
163
|
+
output << {
|
164
|
+
group: group,
|
165
|
+
name: name,
|
166
|
+
description: rewriter.description,
|
167
|
+
sub_snippets: rewriter.sub_snippets.map(&:name)
|
168
|
+
}
|
169
|
+
end
|
186
170
|
end
|
187
|
-
end
|
188
171
|
|
189
|
-
|
172
|
+
puts JSON.generate(output)
|
173
|
+
end
|
190
174
|
end
|
191
175
|
|
192
176
|
# Open one rewriter.
|
@@ -240,6 +224,29 @@ module Synvert
|
|
240
224
|
end
|
241
225
|
end
|
242
226
|
|
227
|
+
# run snippets
|
228
|
+
def run_snippet
|
229
|
+
snippet_name = @options[:snippet_name]
|
230
|
+
if plain_output?
|
231
|
+
puts "===== #{snippet_name} started ====="
|
232
|
+
group, name = snippet_name.split('/')
|
233
|
+
rewriter = Core::Rewriter.call group, name
|
234
|
+
rewriter.warnings.each do |warning|
|
235
|
+
puts '[Warn] ' + warning.message
|
236
|
+
end
|
237
|
+
puts rewriter.todo if rewriter.todo
|
238
|
+
puts "===== #{snippet_name} done ====="
|
239
|
+
elsif json_output?
|
240
|
+
group, name = snippet_name.split('/')
|
241
|
+
rewriter = Core::Rewriter.call group, name
|
242
|
+
puts JSON.generate({
|
243
|
+
affected_files: rewriter.affected_files.union(rewriter.sub_snippets.map(&:affected_files).reduce(:+)).to_a,
|
244
|
+
warnings: rewriter.warnings.union(rewriter.sub_snippets.map(&:warnings).reduce(:+)),
|
245
|
+
todo: rewriter.todo
|
246
|
+
})
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
243
250
|
# generate a new snippet
|
244
251
|
def generate_snippet
|
245
252
|
group, name = @options[:snippet_name].split('/')
|
@@ -250,7 +257,7 @@ module Synvert
|
|
250
257
|
|
251
258
|
Synvert::Rewriter.new '#{group}', '#{name}' do
|
252
259
|
description <<~EOS
|
253
|
-
It
|
260
|
+
It converts Foo to Bar
|
254
261
|
|
255
262
|
```ruby
|
256
263
|
Foo
|
@@ -291,5 +298,13 @@ module Synvert
|
|
291
298
|
def default_snippets_home
|
292
299
|
ENV['SYNVERT_SNIPPETS_HOME'] || File.join(ENV['HOME'], '.synvert')
|
293
300
|
end
|
301
|
+
|
302
|
+
def plain_output?
|
303
|
+
@options[:format] == 'plain'
|
304
|
+
end
|
305
|
+
|
306
|
+
def json_output?
|
307
|
+
@options[:format] == 'json'
|
308
|
+
end
|
294
309
|
end
|
295
310
|
end
|
data/lib/synvert/version.rb
CHANGED
data/synvert.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
spec.post_install_message = 'Please run `synvert --sync` first to sync snippets remotely.'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency 'synvert-core', '>= 0.
|
23
|
+
spec.add_runtime_dependency 'synvert-core', '>= 0.22.0'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler'
|
26
26
|
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
|
+
version: 0.14.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: 2021-03-
|
11
|
+
date: 2021-03-13 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.
|
19
|
+
version: 0.22.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.
|
26
|
+
version: 0.22.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
126
|
+
rubygems_version: 3.0.3
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: synvert = syntax + convert.
|