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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43ccf2486b37c9a73a8f014901e152ff5229bbcac7a35922d6cb5811318c9621
4
- data.tar.gz: 0d9a816901fd978e550f976a6678513a516872f8c41ec3c1a1f21751e8b0a781
3
+ metadata.gz: 5087621370472c9553a89bfe5b75dfed595f07516adba6a421a6b44cffb33e9c
4
+ data.tar.gz: bd29c43ab204f043121b5ce85e49bdc18b8eff2f3ca707a48833d2b773634243
5
5
  SHA512:
6
- metadata.gz: eafeb5f93d44b239f1c48dda8be7426491d126adb1b3ba4a7a17f16b93ec9b48b79db1af3be89a60469891b5b25c4afd31326fc1ef11094fc05d24e0e118f4bc
7
- data.tar.gz: 37c977345a20633089077628dc58d1db3dc7a382f64550f42aa912450437886555f2b372fd4edf1fa54bb6ecdefe222a8a08d9d56af5f8d7e6032252f7eb82c1
6
+ metadata.gz: d3bf4ec96210d9a4dbf1804267809f1e19e9de8147ff3998831428ab3397d23bf38b24519a70850dbd20141b6b0172b636dabaa425c1bf079374e4578f5e36e4
7
+ data.tar.gz: 6b90bd131751a8a50956cdadc21572e70a938a975b71e7deb97c5f48c04184f55b16b3f1fe5b06d95de746df40da3275ce2a19cb50222cf0ebdfc8a3496317c7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.14.0 (2021-03-13)
4
+
5
+ * Add CLI option `--format`
6
+ * Run one snippet once
7
+
3
8
  ## 0.13.0 (2021-03-02)
4
9
 
5
10
  * Use `ENV['SYNVERT_SNIPPETS_HOME']` to change default snippets home
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: [], snippet_names: [] }
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
- @options[:snippet_names].each do |snippet_name|
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 SNIPPET_NAMES',
114
- '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|
115
- @options[:snippet_names] = snippet_names.split(',').map(&:strip)
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
- else
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
- end
168
- end
169
-
170
- def list_all_rewriters_in_json
171
- if Core::Rewriter.availables.empty?
172
- puts 'There is no snippet under ~/.synvert, please run `synvert --sync` to fetch snippets.'
173
- return
174
- end
175
-
176
- output = []
177
- Core::Rewriter.availables.each do |group, rewriters|
178
- rewriters.each do |name, rewriter|
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
- puts JSON.generate(output)
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 convert Foo to Bar
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Synvert
4
- VERSION = '0.13.0'
4
+ VERSION = '0.14.0'
5
5
  end
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.20.1'
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.13.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-02 00:00:00.000000000 Z
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.20.1
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.20.1
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.1.4
126
+ rubygems_version: 3.0.3
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: synvert = syntax + convert.