squared 0.7.13 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,8 +20,8 @@ module Squared
20
20
  include Shell
21
21
  include Prompt
22
22
 
23
- def append(target, *args, delim: false, escape: false, quote: true, strip: nil, force: true, double: false,
24
- filter: nil, pass: nil, preserve: true, **)
23
+ def append(target, *args, delim: false, escape: false, quote: true, strip: nil, double: false, filter: nil,
24
+ pass: nil, **kwargs)
25
25
  return if (ret = args.flatten(1)).empty?
26
26
 
27
27
  target << '--' if delim && !target.include?('--')
@@ -52,7 +52,7 @@ module Squared
52
52
  if !(pa = val.is_a?(Pathname)) && escape
53
53
  shell_escape(val, quote: quote, double: double)
54
54
  elsif quote || pa
55
- shell_quote(val, force: force, double: double, preserve: preserve)
55
+ shell_quote(val, double: double, **kwargs)
56
56
  else
57
57
  val
58
58
  end
@@ -87,25 +87,8 @@ module Squared
87
87
 
88
88
  def strip(val)
89
89
  val = shell_split val if val.is_a?(String)
90
- ret = []
91
- pass = -1
92
- (args = Array(val)).each_with_index do |s, i|
93
- next if s.empty? || pass == i
94
-
95
- if s == '--'
96
- ret << s << args[i.succ..-1].join(' ')
97
- break
98
- end
99
- next ret << s unless s.start_with?('-')
100
-
101
- if !s.include?('=') && (j = args[i.succ]) && !j.start_with?('-')
102
- ret << "#{s.sub(/^-{1,2}/, '')}=#{j}"
103
- pass = i.succ
104
- else
105
- ret << s.sub(OPT_SINGLE, '\1=\2').sub(OPT_VALUE, '\1=\2').sub(OPT_NAME, '\2')
106
- end
107
- end
108
- ret
90
+ Array(val).map { |s| s.sub(OPT_SINGLE, '\1=\2').sub(OPT_VALUE, '\1=\2').sub(OPT_NAME, '\2') }
91
+ .reject(&:empty?)
109
92
  end
110
93
 
111
94
  def select(list, bare: true, no: true, single: false, double: false)
@@ -152,7 +135,7 @@ module Squared
152
135
  [name, $3, $2 || (name.size == 1 && $1.empty? ? true : '')]
153
136
  end
154
137
 
155
- def arg?(target, *args, value: false, **)
138
+ def arg?(target, *args, value: false)
156
139
  r, s = args.partition { |val| val.is_a?(Regexp) }
157
140
  r << matchopts(s, value) unless s.empty?
158
141
  a = target.to_a
@@ -169,11 +152,8 @@ module Squared
169
152
  end
170
153
 
171
154
  def pattern?(val)
172
- Regexp.new(val)
173
155
  val.start_with?('\A', '^') || val.end_with?('\z', '$') ||
174
156
  val.match?(/[.)][*+?]|\(\?[:=!><]|\\[dsw\d]|\[.+\]|\{\d+,?\d*\}/i)
175
- rescue RegexpError
176
- false
177
157
  end
178
158
 
179
159
  private
@@ -271,13 +251,13 @@ module Squared
271
251
  else
272
252
  [flag]
273
253
  end
274
- bare.concat(mod) if val.chomp!('?')
275
- m.concat(mod) if val.chomp!('m')
276
254
  case val[n.succ]
277
255
  when 'e'
278
256
  e.concat(mod)
279
257
  when 'b'
280
258
  b.concat(mod)
259
+ when 'm'
260
+ m.concat(mod)
281
261
  when 'q'
282
262
  qq.concat(mod) if val[n + 2] == 'q'
283
263
  q.concat(mod)
@@ -296,7 +276,11 @@ module Squared
296
276
  when '+'
297
277
  ml.concat(mod)
298
278
  bare.concat(mod)
279
+ else
280
+ next
299
281
  end
282
+ m.concat(mod) if val[n + 2] == 'm'
283
+ bare.concat(mod) if val.end_with?('?')
300
284
  else
301
285
  bare << val
302
286
  mod = [val]
@@ -331,7 +315,7 @@ module Squared
331
315
  end
332
316
  numtype = [
333
317
  [i, /\A\d+\z/],
334
- [f, /\A(\d+(\.\d*)?|\d*\.\d+)\z/],
318
+ [f, /\A\d*(\.\d+)?\z/],
335
319
  [si, /\A-?\d+\z/]
336
320
  ].freeze
337
321
  numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) && v.match?(pat) } }
@@ -364,10 +348,6 @@ module Squared
364
348
  if opt =~ OPT_VALUE
365
349
  key = $1
366
350
  val = $2
367
- if val =~ /\A(["'])(.+)\1\z/
368
- val = $2
369
- double = $1 == '"'
370
- end
371
351
  has = lambda do |a|
372
352
  return true if a.include?(key)
373
353
  return false unless (k = a.find { |s| s.end_with?(':*') })
@@ -375,14 +355,12 @@ module Squared
375
355
  key.start_with?(k.chomp('*')) && !key.end_with?(':')
376
356
  end
377
357
  kwargs = { sep: se[key] || sep, merge: has.call(m), switch: sw[key] }
378
- kwargs[:double] = double unless double.nil?
379
358
  if has.call(e) || (has.call(bl) && %w[true false].include?(val))
380
359
  add shell_option(key, val, **kwargs)
381
360
  elsif has.call(q)
382
- kwargs[:double] = true if has.call(qq)
383
- add quote_option(key, val, **kwargs)
361
+ add quote_option(key, val, double: has.call(qq), **kwargs)
384
362
  elsif has.call(p)
385
- if !double.nil?
363
+ if val.match?(/\A(["']).+\1\z/)
386
364
  add shell_option(key, val, escape: false, **kwargs)
387
365
  elsif path
388
366
  add quote_option(key, path + val, **kwargs)
@@ -631,7 +609,7 @@ module Squared
631
609
  val = OptionPartition.send(:matchopts, val) unless val.is_a?(Regexp)
632
610
  blk = proc { |s| s&.match?(val) }
633
611
  else
634
- raise TypeError, "unknown: #{val}"
612
+ raise TypeError, Common::Format.message('unknown', val, hint: target.first)
635
613
  end
636
614
  end
637
615
  ret = find_all(&blk)
@@ -680,10 +658,7 @@ module Squared
680
658
 
681
659
  def readline(msg, fallback = nil, option: nil, quote: false, force: true, double: false)
682
660
  begin
683
- require 'readline' unless defined?(Readline)
684
- ret = Readline.readline("#{msg}#{force ? ':' : '?'} ", false).strip
685
- rescue LoadError
686
- raise unless (ret = fallback) || !force
661
+ ret = Common::Prompt.reline.readline("#{msg}#{force ? ':' : '?'} ", false).strip
687
662
  rescue Interrupt
688
663
  exit(force ? 1 : 0)
689
664
  else
@@ -7,6 +7,15 @@ module Squared
7
7
  module Utils
8
8
  private
9
9
 
10
+ def symjoin(*args, char: ':')
11
+ args.flatten.join(char).to_sym
12
+ end
13
+
14
+ def collect_hash(data, pass: [])
15
+ data = data.reject { |key,| pass.include?(key) } unless pass.empty?
16
+ data.values.flatten
17
+ end
18
+
10
19
  def rand_s(size)
11
20
  require 'random/formatter'
12
21
  Random.new.alphanumeric(size)
@@ -26,29 +35,13 @@ module Squared
26
35
  end
27
36
  end
28
37
 
29
- def matchmap(list, prefix = nil, negate: false)
30
- ret = negate ? [[], []] : []
31
- list.each do |val|
32
- unless val.is_a?(Regexp)
33
- val = val.dup
34
- n = 1 if negate && val.delete_prefix!('!')
35
- if prefix
36
- a = nil
37
- val.sub!(/\A(\^|\\A)/) do |s|
38
- a = s
39
- nil
40
- end
41
- val = ".*#{val}" unless a
42
- end
43
- end
44
- pat = Regexp.new("#{a}#{prefix}#{val == '*' ? '.+' : val}")
45
- if negate
46
- ret[n || 0] << pat
47
- else
48
- ret << pat
49
- end
38
+ def matchmap(list, prefix: nil)
39
+ list.map do |val|
40
+ next val if val.is_a?(Regexp)
41
+
42
+ val = ".*#{val}" if prefix && !val.sub!(/\A(\^|\\A)/, '')
43
+ Regexp.new("#{prefix}#{val == '*' ? '.+' : val}")
50
44
  end
51
- ret
52
45
  end
53
46
 
54
47
  def matchany?(list, *args, empty: true)
@@ -20,7 +20,7 @@ module Squared
20
20
  elsif !repo_install? && !repo_confirm
21
21
  @root = nil
22
22
  end
23
- raise_error Errno::EEXIST, path.cleanpath, hint: 'REPO_HOME' unless @root
23
+ raise Errno::EEXIST, message(path.cleanpath, hint: 'REPO_HOME') unless @root
24
24
  end
25
25
  path.realdirpath
26
26
  elsif (val = env('REPO_ROOT'))
@@ -28,7 +28,7 @@ module Squared
28
28
  if !@root.exist?
29
29
  @root.mkpath
30
30
  elsif !repo_install?(parent: true) && !repo_confirm
31
- raise_error Errno::EEXIST, @root, hint: 'REPO_ROOT'
31
+ raise Errno::EEXIST, message(@root, hint: 'REPO_ROOT')
32
32
  end
33
33
  @root.join(main).realdirpath
34
34
  elsif repo_install?(parent: true) && (!home.exist? || @root + main == home)
@@ -157,6 +157,8 @@ module Squared
157
157
  [proj, proj.build? && (script || run), doc && proj.doc?, lint && proj.lint?, test && proj.test?]
158
158
  end
159
159
  .select do |proj, run, doc, lint, test|
160
+ next unless proj
161
+
160
162
  proj.doc(sync: true) if doc
161
163
  proj.build(sync: true) if run
162
164
  next if n.anybits?(4)
@@ -184,7 +186,8 @@ module Squared
184
186
  end
185
187
  env('REPO_GROUPS', **envargs) do |val|
186
188
  g = case val
187
- when '0', 'false' then nil
189
+ when '0', 'false'
190
+ nil
188
191
  else
189
192
  val
190
193
  end
@@ -274,13 +277,13 @@ module Squared
274
277
  end
275
278
  end
276
279
 
277
- def repo_run(cmd, opts = [], exception: false, options: true, **kwargs)
280
+ def repo_run(cmd, opts = [], exception: exception?, options: true, **kwargs)
278
281
  cmd = [repo_bin, cmd]
279
282
  cmd << opts.uniq.join(' ') unless opts.empty?
280
283
  env('REPO_OPTIONS', **kwargs) { |val| cmd << val } if options
281
284
  cmd = cmd.join(' ')
282
285
  puts log_message(cmd, subject: main, hint: root) if verbose
283
- Common::System.shell(cmd, chdir: root, exception: exception || env('REPO_FAIL', equals: %w[1 true]))
286
+ Common::System.shell(cmd, chdir: root, exception: exception)
284
287
  end
285
288
 
286
289
  def repo_bin
@@ -307,7 +310,7 @@ module Squared
307
310
  r = r.keys
308
311
  pass = g.empty? && r.empty?
309
312
  select do |proj|
310
- next unless proj.enabled?(baseref)
313
+ next unless proj.enabled?(ref: baseref)
311
314
 
312
315
  proj.global_set(name)
313
316
  i = -1
@@ -338,7 +341,7 @@ module Squared
338
341
  task_invoke(name, **proj.workspace.invokeargs)
339
342
  end
340
343
  rescue => e
341
- raise if exception
344
+ raise if exception?
342
345
 
343
346
  warn log_warn(e, pass: true) if warning
344
347
  end
@@ -38,10 +38,18 @@ module Squared
38
38
  end
39
39
  end
40
40
  if (args = obj.batchargs)
41
- batch_set(*args)
41
+ if args.first.is_a?(Hash)
42
+ batch_set(obj.ref, *args)
43
+ else
44
+ batch_set(*args)
45
+ end
42
46
  end
43
47
  if (args = obj.aliasargs)
44
- alias_set(*args)
48
+ if args.first.is_a?(Hash)
49
+ alias_set(obj.ref, *args)
50
+ else
51
+ alias_set(*args)
52
+ end
45
53
  end
46
54
  end
47
55
  workspace.config_get(:batch)&.each { |args| batch_set(*args) }
@@ -209,9 +217,8 @@ module Squared
209
217
  already_invoked? parallel, val
210
218
  end
211
219
 
212
- def exclude?(key, fallback = false, empty: nil)
213
- fallback = empty unless empty.nil?
214
- @exclude.include?(key) || (fallback && (!key?(key) || self[key].empty?))
220
+ def exclude?(key, empty = false)
221
+ @exclude.include?(key) || (empty && (!key?(key) || self[key].empty?))
215
222
  end
216
223
 
217
224
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.13
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 4.0.20
128
+ rubygems_version: 4.0.10
129
129
  specification_version: 4
130
130
  summary: Rake task generator for managing multi-language workspaces.
131
131
  test_files: []