squared 0.7.3 → 0.7.5

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.
@@ -65,14 +65,14 @@ module Squared
65
65
  ret
66
66
  end
67
67
 
68
- def clear(target, opts, pass: true, styles: nil, **kwargs)
68
+ def clear(target, opts, pass: true, strict: false, styles: nil, **kwargs)
69
69
  return if opts.empty?
70
70
 
71
71
  kwargs[:subject] ||= target.first.stripext
72
72
  kwargs[:hint] ||= 'unrecognized'
73
73
  append(target, opts, delim: true) if kwargs.delete(:append)
74
74
  warn log_warn(opts.join(', '), pass: true, **kwargs)
75
- exit 1 unless pass || confirm("Run? [#{sub_style(target, styles)}]", 'N')
75
+ exit 1 unless !strict && (pass || confirm("Run? [#{sub_style(target, styles)}]", 'N'))
76
76
  end
77
77
 
78
78
  def delete_key(target, *args, value: false, reverse: false, count: -1)
@@ -195,10 +195,12 @@ module Squared
195
195
  def_delegator :@extras, :find_all, :detect_all
196
196
  def_delegator :@extras, :find_index, :detect_index
197
197
 
198
- def initialize(opts, list, target = JoinSet.new, project: nil, path: nil, sep: '=', **kwargs, &blk)
198
+ def initialize(opts, list, target = JoinSet.new, project: nil, path: nil, strict: false, sep: '=', **kwargs,
199
+ &blk)
199
200
  @target = target.is_a?(Set) ? target : target.to_set
200
201
  @project = project
201
202
  @path = path || project&.path
203
+ @strict = strict
202
204
  @sep = sep
203
205
  @errors = []
204
206
  @found = []
@@ -242,42 +244,51 @@ module Squared
242
244
  end
243
245
  if (n = val.index('='))
244
246
  flag = val[0, n]
247
+ enum = flag.split(':')
248
+ mod = if enum.size > 1
249
+ pre = enum.shift
250
+ enum.map { |s| "#{pre}:#{s}" }
251
+ else
252
+ [flag]
253
+ end
245
254
  case val[n.succ]
246
255
  when 'e'
247
- e << flag
256
+ e.concat(mod)
248
257
  when 'b'
249
- b << flag
258
+ b.concat(mod)
250
259
  when 'm'
251
- m << flag
260
+ m.concat(mod)
252
261
  when 'q'
253
- qq << flag if val[n + 2] == 'q'
254
- q << flag
262
+ qq.concat(mod) if val[n + 2] == 'q'
263
+ q.concat(mod)
255
264
  when 'p'
256
- p << flag
265
+ p.concat(mod)
257
266
  when 'i'
258
- i << flag
267
+ i.concat(mod)
259
268
  when 'f'
260
- f << flag
269
+ f.concat(mod)
261
270
  when 'n'
262
- si << flag
271
+ si.concat(mod)
263
272
  when 'v'
264
- @values << Regexp.escape(flag)
273
+ @values.concat(mod.map { |s| Regexp.escape(s) })
265
274
  when '!'
266
- bl << flag
275
+ bl.concat(mod)
267
276
  when '+'
268
- ml << flag
269
- bare << flag
277
+ ml.concat(mod)
278
+ bare.concat(mod)
270
279
  else
271
280
  next
272
281
  end
273
- m << flag if val[n + 2] == 'm'
274
- bare << flag if val.end_with?('?')
275
- val = flag
282
+ m.concat(mod) if val[n + 2] == 'm'
283
+ bare.concat(mod) if val.end_with?('?')
276
284
  else
277
285
  bare << val
286
+ mod = [val]
287
+ end
288
+ mod.each do |key|
289
+ sw[key] = op1 if op1
290
+ se[key] = op2 if op2
278
291
  end
279
- sw[val] = op1 if op1
280
- se[val] = op2 if op2
281
292
  end
282
293
  no = (no || []).map { |val| (n = val.index('=')) ? val[0, n] : val }
283
294
  bare.concat(no)
@@ -337,14 +348,18 @@ module Squared
337
348
  if opt =~ OPT_VALUE
338
349
  key = $1
339
350
  val = $2
340
- merge = m.include?(key)
341
- switch = sw[key]
342
- kwargs = { sep: se[key] || sep, merge: merge, switch: switch }
343
- if e.include?(key) || (bl.include?(key) && %w[true false].include?(val))
351
+ has = lambda do |a|
352
+ return true if a.include?(key)
353
+ return false unless (k = a.find { |s| s.end_with?(':*') })
354
+
355
+ key.start_with?(k.chomp('*')) && !key.end_with?(':')
356
+ end
357
+ kwargs = { sep: se[key] || sep, merge: has.call(m), switch: sw[key] }
358
+ if has.call(e) || (has.call(bl) && %w[true false].include?(val))
344
359
  add shell_option(key, val, **kwargs)
345
- elsif q.include?(key)
346
- add quote_option(key, val, double: qq.include?(key), **kwargs)
347
- elsif p.include?(key)
360
+ elsif has.call(q)
361
+ add quote_option(key, val, double: has.call(qq), **kwargs)
362
+ elsif has.call(p)
348
363
  if val.match?(/\A(["']).+\1\z/)
349
364
  add shell_option(key, val, escape: false, **kwargs)
350
365
  elsif path
@@ -352,7 +367,7 @@ module Squared
352
367
  else
353
368
  push opt
354
369
  end
355
- elsif b.include?(key) || numcheck.call(key, val) || se[key] || merge || switch
370
+ elsif kwargs[:merge] || has.call(b) || numcheck.call(key, val) || se[key] || sw[key]
356
371
  add basic_option(key, val, **kwargs)
357
372
  else
358
373
  push opt
@@ -380,8 +395,8 @@ module Squared
380
395
  self
381
396
  end
382
397
 
383
- def append(*args, **kwargs, &blk)
384
- args = extras if args.empty?
398
+ def append(*args, clear: false, **kwargs, &blk)
399
+ args = clear ? extras.dup.tap { extras.clear } : extras if args.empty?
385
400
  pass = kwargs[:pass] ||= []
386
401
  OptionPartition.append(target, *args, **kwargs, &blk)
387
402
  errors.concat(pass)
@@ -459,15 +474,15 @@ module Squared
459
474
  list.reject { |val| ignore.include?(s = nameonly(val)) || any?(OptionPartition.send(:matchopt, s)) }
460
475
  end
461
476
 
462
- def clear(opts = nil, errors: false, **kwargs)
477
+ def clear(opts = nil, errors: false, strict: @strict, **kwargs)
463
478
  styles = project.theme[:inline] if project
464
479
  if errors
465
- OptionPartition.clear(target, @errors, styles: styles, **kwargs)
480
+ OptionPartition.clear(target, @errors, strict: strict, styles: styles, **kwargs)
466
481
  @errors.clear
467
482
  return self unless opts
468
483
  end
469
484
  opts ||= extras
470
- OptionPartition.clear(target, opts - found, styles: styles, **kwargs)
485
+ OptionPartition.clear(target, opts - found, strict: strict, styles: styles, **kwargs)
471
486
  opts.clear
472
487
  self
473
488
  end
@@ -641,6 +656,29 @@ module Squared
641
656
  self
642
657
  end
643
658
 
659
+ def readline(msg, fallback = nil, option: nil, quote: false, force: true, double: false)
660
+ begin
661
+ require 'readline' unless defined?(Readline)
662
+ ret = Readline.readline("#{msg}#{force ? ':' : '?'} ", false).strip
663
+ rescue LoadError
664
+ raise unless (ret = fallback) || !force
665
+ rescue Interrupt
666
+ exit(force ? 1 : 0)
667
+ else
668
+ exit 1 if ret.empty? && !(ret = fallback) && force
669
+ end
670
+ return unless ret
671
+
672
+ if option
673
+ add quote_option(option, ret, double: double)
674
+ elsif quote
675
+ add shell_quote(ret, option: false, double: double)
676
+ else
677
+ add ret
678
+ end
679
+ ret
680
+ end
681
+
644
682
  def reset(errors: false)
645
683
  extras.clear
646
684
  found.clear
@@ -8,12 +8,10 @@ module Squared
8
8
  private
9
9
 
10
10
  def rand_s(size)
11
- if RUBY_VERSION >= '3.1'
12
- require 'random/formatter'
13
- Random.new.alphanumeric(size)
14
- else
15
- (0...size).map { rand(97..122).chr }.join
16
- end
11
+ require 'random/formatter'
12
+ Random.new.alphanumeric(size)
13
+ rescue LoadError
14
+ (0...size).map { rand(97..122).chr }.join
17
15
  end
18
16
 
19
17
  def merge_list(target, list)
@@ -47,8 +47,8 @@ module Squared
47
47
  envargs = name ? { suffix: name.upcase, strict: true } : {}
48
48
  data = scriptobj
49
49
  if repo?
50
- group = env('REPO_GROUP', **envargs) { |val| split_escape(val) }
51
- ref = env('REPO_REF', **envargs) { |val| split_escape(val) }
50
+ env('REPO_GROUP', **envargs) { |s| group = split_escape(s) }
51
+ env('REPO_REF', **envargs) { |s| ref = split_escape(s) }
52
52
  data[:dev] = env_match('REPO_DEV', dev, **envargs)
53
53
  data[:prod] = env_match('REPO_PROD', prod, **envargs)
54
54
  @warning = env_match('REPO_WARN', @warning && !root?(@root, pass: ['.repo'])) != false unless name
@@ -76,7 +76,7 @@ module Squared
76
76
  sc
77
77
  end
78
78
  end
79
- data[:args] = env('REPO_SCRIPT', **envargs) { |val| shell_split(val, join: true) } || args
79
+ data[:args] = env('REPO_SCRIPT', **envargs) { |s| shell_split(s, join: true) } || args
80
80
  global[:script] = true
81
81
  else
82
82
  ru ||= sc
@@ -207,7 +207,8 @@ module Squared
207
207
  opts = if stage == 'init'
208
208
  []
209
209
  else
210
- raise_error 'repo not initialized' unless branch
210
+ raise 'repo not initialized' unless branch
211
+
211
212
  repo_opts
212
213
  end
213
214
  args.to_a.each do |val|
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.3
4
+ version: 0.7.5
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.3
128
+ rubygems_version: 4.0.6
129
129
  specification_version: 4
130
130
  summary: Rake task generator for managing multi-language workspaces.
131
131
  test_files: []