squared 0.5.13 → 0.6.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +108 -0
- data/README.md +75 -34
- data/lib/squared/common/base.rb +1 -22
- data/lib/squared/common/format.rb +32 -24
- data/lib/squared/common/prompt.rb +55 -32
- data/lib/squared/common/shell.rb +42 -5
- data/lib/squared/common/system.rb +69 -36
- data/lib/squared/common/utils.rb +29 -6
- data/lib/squared/config.rb +17 -21
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +80 -81
- data/lib/squared/workspace/project/base.rb +497 -333
- data/lib/squared/workspace/project/docker.rb +375 -273
- data/lib/squared/workspace/project/git.rb +346 -326
- data/lib/squared/workspace/project/node.rb +485 -254
- data/lib/squared/workspace/project/python.rb +328 -199
- data/lib/squared/workspace/project/ruby.rb +770 -342
- data/lib/squared/workspace/project/support/class.rb +166 -68
- data/lib/squared/workspace/repo.rb +38 -34
- data/lib/squared/workspace/series.rb +6 -6
- data/lib/squared/workspace/support/base.rb +3 -24
- data/lib/squared/workspace/support/variables.rb +48 -0
- data/lib/squared/workspace/support.rb +1 -1
- data/lib/squared/workspace.rb +1 -1
- metadata +2 -2
- data/lib/squared/workspace/support/data.rb +0 -11
|
@@ -21,7 +21,7 @@ module Squared
|
|
|
21
21
|
include Prompt
|
|
22
22
|
|
|
23
23
|
def append(target, *args, delim: false, escape: false, quote: true, strip: nil, force: true, double: false,
|
|
24
|
-
**)
|
|
24
|
+
filter: nil, **)
|
|
25
25
|
return if (ret = args.flatten).empty?
|
|
26
26
|
|
|
27
27
|
target << '--' if delim && !target.include?('--')
|
|
@@ -29,6 +29,22 @@ module Squared
|
|
|
29
29
|
pat, s = Array(strip)
|
|
30
30
|
ret.map! { |val| val.gsub(pat, s || '') }
|
|
31
31
|
end
|
|
32
|
+
ret, err = ret.partition { |val| filter.match?(val) } if filter
|
|
33
|
+
if block_given?
|
|
34
|
+
out = []
|
|
35
|
+
err ||= []
|
|
36
|
+
ret.each do |val|
|
|
37
|
+
case (s = yield val)
|
|
38
|
+
when String
|
|
39
|
+
out << s
|
|
40
|
+
when NilClass, FalseClass
|
|
41
|
+
err << val
|
|
42
|
+
else
|
|
43
|
+
out << val
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
ret = out
|
|
47
|
+
end
|
|
32
48
|
if escape || quote
|
|
33
49
|
ret.map! do |val|
|
|
34
50
|
if opt?(val)
|
|
@@ -45,13 +61,13 @@ module Squared
|
|
|
45
61
|
else
|
|
46
62
|
target.concat(ret)
|
|
47
63
|
end
|
|
48
|
-
ret
|
|
64
|
+
err || ret
|
|
49
65
|
end
|
|
50
66
|
|
|
51
67
|
def clear(target, opts, pass: true, styles: nil, **kwargs)
|
|
52
68
|
return if opts.empty?
|
|
53
69
|
|
|
54
|
-
kwargs[:subject] ||=
|
|
70
|
+
kwargs[:subject] ||= target.first.stripext
|
|
55
71
|
kwargs[:hint] ||= 'unrecognized'
|
|
56
72
|
append(target, opts, delim: true) if kwargs.delete(:append)
|
|
57
73
|
warn log_message(Logger::WARN, opts.join(', '), pass: true, **kwargs)
|
|
@@ -86,6 +102,20 @@ module Squared
|
|
|
86
102
|
ret.select { |val| single ? val.size == 1 : val.size > 1 }
|
|
87
103
|
end
|
|
88
104
|
|
|
105
|
+
def uniq!(list, pass = [])
|
|
106
|
+
keys = {}
|
|
107
|
+
list.each_with_index do |val, i|
|
|
108
|
+
j = val =~ OPT_VALUE ? $1 : val
|
|
109
|
+
(keys[j] ||= []) << i unless pass.include?(j)
|
|
110
|
+
end
|
|
111
|
+
data = keys.map { |item| item[1].size > 1 ? item[1][0..-2] : [] }.reject(&:empty?)
|
|
112
|
+
return if data.empty?
|
|
113
|
+
|
|
114
|
+
data.each { |key| key.each { |i| list[i] = nil } }
|
|
115
|
+
list.compact!
|
|
116
|
+
list
|
|
117
|
+
end
|
|
118
|
+
|
|
89
119
|
def arg?(target, *args, value: false, **)
|
|
90
120
|
r, s = args.partition { |val| val.is_a?(Regexp) }
|
|
91
121
|
r << matchopts(s, value) unless s.empty?
|
|
@@ -126,13 +156,12 @@ module Squared
|
|
|
126
156
|
end
|
|
127
157
|
end
|
|
128
158
|
|
|
129
|
-
attr_reader :target, :extras, :found, :errors, :values, :project, :path
|
|
159
|
+
attr_reader :target, :extras, :found, :errors, :values, :project, :path, :sep
|
|
130
160
|
|
|
131
161
|
def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
|
|
132
162
|
:merge, :delete, :delete?, :delete_if, :grep, :grep_v, :inspect, :to_a, :to_s
|
|
133
|
-
def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :
|
|
134
|
-
:pop, :push, :concat, :index, :join, :map, :map!, :detect, :select, :select!, :reject, :size
|
|
135
|
-
:delete_at
|
|
163
|
+
def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :shift, :unshift,
|
|
164
|
+
:pop, :push, :concat, :index, :join, :map, :map!, :detect, :select, :select!, :reject, :size
|
|
136
165
|
|
|
137
166
|
def_delegator :@extras, :delete, :remove
|
|
138
167
|
def_delegator :@extras, :delete_at, :remove_at
|
|
@@ -140,10 +169,11 @@ module Squared
|
|
|
140
169
|
def_delegator :@extras, :find_all, :detect_all
|
|
141
170
|
def_delegator :@extras, :find_index, :detect_index
|
|
142
171
|
|
|
143
|
-
def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
|
|
172
|
+
def initialize(opts, list, target = Set.new, project: nil, path: nil, sep: '=', **kwargs, &blk)
|
|
144
173
|
@target = target.is_a?(Set) ? target : target.to_set
|
|
145
174
|
@project = project
|
|
146
175
|
@path = path || project&.path
|
|
176
|
+
@sep = sep
|
|
147
177
|
@errors = []
|
|
148
178
|
@found = []
|
|
149
179
|
parse(list, opts, **kwargs, &blk)
|
|
@@ -177,7 +207,7 @@ module Squared
|
|
|
177
207
|
.each do |val|
|
|
178
208
|
if (n = val.index('='))
|
|
179
209
|
flag = val[0, n]
|
|
180
|
-
case val[n
|
|
210
|
+
case val[n.succ]
|
|
181
211
|
when 'e'
|
|
182
212
|
e << flag
|
|
183
213
|
when 'b'
|
|
@@ -202,7 +232,7 @@ module Squared
|
|
|
202
232
|
else
|
|
203
233
|
next
|
|
204
234
|
end
|
|
205
|
-
m << flag if
|
|
235
|
+
m << flag if val[n + 2] == 'm'
|
|
206
236
|
bare << flag if val.end_with?('?')
|
|
207
237
|
else
|
|
208
238
|
bare << val
|
|
@@ -211,7 +241,7 @@ module Squared
|
|
|
211
241
|
no = (no || []).map { |val| (n = val.index('=')) ? val[0, n] : val }
|
|
212
242
|
bare.concat(no)
|
|
213
243
|
if underscore
|
|
214
|
-
tr = ->(
|
|
244
|
+
tr = ->(a) { a.map { |val| val.tr('-', '_') } }
|
|
215
245
|
@values.concat(tr.call(@values))
|
|
216
246
|
bare.concat(tr.call(bare))
|
|
217
247
|
e.concat(tr.call(e))
|
|
@@ -231,7 +261,7 @@ module Squared
|
|
|
231
261
|
[f, /\A\d*(?:\.\d+)?\z/],
|
|
232
262
|
[si, /\A-?\d+\z/]
|
|
233
263
|
].freeze
|
|
234
|
-
numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) &&
|
|
264
|
+
numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) && v.match?(pat) } }
|
|
235
265
|
skip = false
|
|
236
266
|
opts.each do |opt|
|
|
237
267
|
next skip = true if opt == '--'
|
|
@@ -249,21 +279,21 @@ module Squared
|
|
|
249
279
|
val = $2
|
|
250
280
|
merge = m.include?(key)
|
|
251
281
|
if e.include?(key)
|
|
252
|
-
add shell_option(key, val, merge: merge)
|
|
282
|
+
add shell_option(key, val, merge: merge, sep: sep)
|
|
253
283
|
elsif q.include?(key)
|
|
254
|
-
add quote_option(key, val, double: qq.include?(key), merge: merge)
|
|
284
|
+
add quote_option(key, val, double: qq.include?(key), merge: merge, sep: sep)
|
|
255
285
|
elsif p.include?(key)
|
|
256
286
|
if val.match?(/\A(["']).+\1\z/)
|
|
257
|
-
add shell_option(key, val, escape: false, merge: merge)
|
|
287
|
+
add shell_option(key, val, escape: false, merge: merge, sep: sep)
|
|
258
288
|
elsif path
|
|
259
|
-
add quote_option(key, path + val, merge: merge)
|
|
289
|
+
add quote_option(key, path + val, merge: merge, sep: sep)
|
|
260
290
|
else
|
|
261
291
|
push opt
|
|
262
292
|
end
|
|
263
293
|
elsif b.include?(key) || (bl.include?(key) && %w[true false].include?(val)) || numcheck.call(key, val)
|
|
264
|
-
add basic_option(key, val, merge: merge)
|
|
294
|
+
add basic_option(key, val, merge: merge, sep: sep)
|
|
265
295
|
elsif merge
|
|
266
|
-
add basic_option(key, val, merge: true)
|
|
296
|
+
add basic_option(key, val, merge: true, sep: sep)
|
|
267
297
|
else
|
|
268
298
|
push opt
|
|
269
299
|
end
|
|
@@ -275,28 +305,33 @@ module Squared
|
|
|
275
305
|
skip = true if first&.any? { |s| s.is_a?(Regexp) ? opt.match?(s) : !opt.include?(s) }
|
|
276
306
|
end
|
|
277
307
|
end
|
|
278
|
-
@values = @values.empty? ? /\A\s+\z/ : /\A(#{@values.join('|')})
|
|
308
|
+
@values = @values.empty? ? /\A\s+\z/ : /\A(#{@values.join('|')})#{sep}(.+)\z/m
|
|
279
309
|
@extras.each_with_index(&blk) if block_given?
|
|
280
310
|
self
|
|
281
311
|
end
|
|
282
312
|
|
|
283
|
-
def swap(opts = nil)
|
|
313
|
+
def swap(opts = nil, &blk)
|
|
284
314
|
unless opts
|
|
285
315
|
opts = found
|
|
286
316
|
@found = []
|
|
287
317
|
end
|
|
318
|
+
opts.sort!(&blk) if block_given?
|
|
288
319
|
@extras = opts
|
|
289
320
|
self
|
|
290
321
|
end
|
|
291
322
|
|
|
292
|
-
def append(*args, **kwargs)
|
|
323
|
+
def append(*args, **kwargs, &blk)
|
|
293
324
|
args = extras if args.empty?
|
|
294
|
-
OptionPartition.append(target, *args, **kwargs)
|
|
325
|
+
out = OptionPartition.append(target, *args, **kwargs, &blk)
|
|
326
|
+
errors.concat(out) if out && (block_given? || kwargs[:filter])
|
|
295
327
|
self
|
|
296
328
|
end
|
|
297
329
|
|
|
298
330
|
def append_any(*args, quote: true, **kwargs)
|
|
299
331
|
(args.empty? ? extras : args.flatten).each do |val|
|
|
332
|
+
val = yield val if block_given?
|
|
333
|
+
next unless val.is_a?(String)
|
|
334
|
+
|
|
300
335
|
if exist?(val)
|
|
301
336
|
add_path(val, **kwargs)
|
|
302
337
|
elsif quote
|
|
@@ -314,7 +349,7 @@ module Squared
|
|
|
314
349
|
end
|
|
315
350
|
|
|
316
351
|
def values_of(*args, strict: true, first: false, last: false)
|
|
317
|
-
eq, s = strict ? [
|
|
352
|
+
eq, s = strict ? [sep, '[^ ]+'] : ['(?:=| +)', '[^-][^ ]*']
|
|
318
353
|
g = ["\"((?:[^\"]|(?<=\\\\)\"(?!$#{windows? ? '| ' : ''}))*)\""]
|
|
319
354
|
g << "'((?:[^']|'\\\\'')*)'" unless windows?
|
|
320
355
|
g << "(#{s})"
|
|
@@ -353,22 +388,18 @@ module Squared
|
|
|
353
388
|
def clear(opts = nil, errors: false, **kwargs)
|
|
354
389
|
styles = project.theme[:inline] if project
|
|
355
390
|
if errors
|
|
356
|
-
OptionPartition.clear(target,
|
|
357
|
-
|
|
391
|
+
OptionPartition.clear(target, @errors, styles: styles, **kwargs)
|
|
392
|
+
@errors.clear
|
|
358
393
|
return self unless opts
|
|
359
394
|
end
|
|
360
395
|
opts ||= extras
|
|
361
|
-
OptionPartition.clear(target,
|
|
362
|
-
opts
|
|
363
|
-
else
|
|
364
|
-
opts.reject { |val| found.include?(val) }
|
|
365
|
-
end, styles: styles, **kwargs)
|
|
396
|
+
OptionPartition.clear(target, opts - found, styles: styles, **kwargs)
|
|
366
397
|
opts.clear
|
|
367
398
|
self
|
|
368
399
|
end
|
|
369
400
|
|
|
370
401
|
def adjoin(*args, with: nil, start: false)
|
|
371
|
-
|
|
402
|
+
index = -1
|
|
372
403
|
temp = to_a
|
|
373
404
|
if with
|
|
374
405
|
pat = case with
|
|
@@ -379,44 +410,50 @@ module Squared
|
|
|
379
410
|
else
|
|
380
411
|
with
|
|
381
412
|
end
|
|
382
|
-
temp.each_with_index do |val,
|
|
413
|
+
temp.each_with_index do |val, i|
|
|
383
414
|
if val.to_s.match?(pat)
|
|
384
|
-
|
|
415
|
+
index = i + (start.is_a?(Numeric) ? start : 1)
|
|
385
416
|
break
|
|
386
417
|
end
|
|
387
418
|
end
|
|
388
419
|
else
|
|
389
|
-
temp.each_with_index do |val,
|
|
390
|
-
if
|
|
420
|
+
temp.each_with_index do |val, i|
|
|
421
|
+
if index == 0
|
|
391
422
|
next unless val.start_with?('-')
|
|
392
423
|
|
|
393
|
-
|
|
424
|
+
index = i
|
|
394
425
|
break
|
|
395
|
-
elsif
|
|
426
|
+
elsif i > 0 && !val.start_with?('-')
|
|
396
427
|
if start
|
|
397
|
-
|
|
428
|
+
index = i + (start.is_a?(Numeric) ? start : 1)
|
|
398
429
|
break
|
|
399
430
|
end
|
|
400
|
-
|
|
431
|
+
index = 0
|
|
401
432
|
end
|
|
402
433
|
end
|
|
403
434
|
end
|
|
404
|
-
if
|
|
435
|
+
if index > 0
|
|
405
436
|
if args.empty?
|
|
406
437
|
args = dup
|
|
407
438
|
reset
|
|
408
439
|
else
|
|
409
440
|
args.each { |val| remove val }
|
|
410
441
|
end
|
|
411
|
-
args = temp[0...
|
|
442
|
+
args = temp[0...index] + args + temp[index..-1]
|
|
412
443
|
target.clear
|
|
413
444
|
end
|
|
414
445
|
merge args
|
|
415
446
|
self
|
|
416
447
|
end
|
|
417
448
|
|
|
418
|
-
def add_path(*args, **kwargs)
|
|
419
|
-
|
|
449
|
+
def add_path(*args, force: true, double: false, **kwargs)
|
|
450
|
+
if args.empty?
|
|
451
|
+
args = select { |val| val.is_a?(String) }
|
|
452
|
+
args.map! { |val| path + val } if path
|
|
453
|
+
append(args, force: force, **kwargs)
|
|
454
|
+
else
|
|
455
|
+
add shell_quote(path ? path.join(*args) : File.join(*args), option: false, force: force, double: double)
|
|
456
|
+
end
|
|
420
457
|
self
|
|
421
458
|
end
|
|
422
459
|
|
|
@@ -426,6 +463,62 @@ module Squared
|
|
|
426
463
|
self
|
|
427
464
|
end
|
|
428
465
|
|
|
466
|
+
def add_option(flag, val = nil, **kwargs)
|
|
467
|
+
add shell_option(flag, val, **kwargs)
|
|
468
|
+
self
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
def add_first(fallback = nil, prefix: nil, path: false, quote: false, reverse: false, expect: false, **kwargs)
|
|
472
|
+
val = (reverse ? pop : shift) || fallback
|
|
473
|
+
if val
|
|
474
|
+
val.delete_prefix!(prefix) if prefix
|
|
475
|
+
return self if block_given? && !(val = yield val).is_a?(String)
|
|
476
|
+
|
|
477
|
+
if path
|
|
478
|
+
add_path(val, **kwargs)
|
|
479
|
+
elsif quote
|
|
480
|
+
add_quote(val, **kwargs)
|
|
481
|
+
else
|
|
482
|
+
add val
|
|
483
|
+
end
|
|
484
|
+
elsif expect
|
|
485
|
+
raise(expect.is_a?(String) ? expect : 'no value provided')
|
|
486
|
+
end
|
|
487
|
+
self
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
def last(val = nil, &blk)
|
|
491
|
+
unless block_given?
|
|
492
|
+
case val
|
|
493
|
+
when NilClass
|
|
494
|
+
return extras.last
|
|
495
|
+
when Numeric
|
|
496
|
+
return extras.last(val)
|
|
497
|
+
when String, Array, Regexp
|
|
498
|
+
val = OptionPartition.send(:matchopts, val) unless val.is_a?(Regexp)
|
|
499
|
+
blk = proc { |s| s&.match?(val) }
|
|
500
|
+
else
|
|
501
|
+
raise TypeError, "unknown: #{val}"
|
|
502
|
+
end
|
|
503
|
+
end
|
|
504
|
+
ret = find_all(&blk)
|
|
505
|
+
unless ret.empty?
|
|
506
|
+
ret = case val
|
|
507
|
+
when NilClass
|
|
508
|
+
ret.first(1)
|
|
509
|
+
when Numeric
|
|
510
|
+
ret.first(val)
|
|
511
|
+
else
|
|
512
|
+
ret
|
|
513
|
+
end
|
|
514
|
+
ret.each do |opt|
|
|
515
|
+
delete opt
|
|
516
|
+
add opt
|
|
517
|
+
end
|
|
518
|
+
end
|
|
519
|
+
val.nil? ? ret.first : ret
|
|
520
|
+
end
|
|
521
|
+
|
|
429
522
|
def splice(*exclude, quote: true, delim: true, path: false, pattern: false, &blk)
|
|
430
523
|
found, other = if block_given?
|
|
431
524
|
partition(&blk)
|
|
@@ -459,7 +552,7 @@ module Squared
|
|
|
459
552
|
self
|
|
460
553
|
end
|
|
461
554
|
|
|
462
|
-
def append?(key, val = nil, type: nil, force: false, **kwargs)
|
|
555
|
+
def append?(key, val = nil, type: nil, force: false, sep: '=', **kwargs)
|
|
463
556
|
return false unless force || !arg?(key)
|
|
464
557
|
|
|
465
558
|
val = yield self if block_given?
|
|
@@ -468,11 +561,11 @@ module Squared
|
|
|
468
561
|
type ||= :quote if kwargs.empty?
|
|
469
562
|
add case type
|
|
470
563
|
when :quote
|
|
471
|
-
quote_option(key, val)
|
|
564
|
+
quote_option(key, val, sep: sep)
|
|
472
565
|
when :basic
|
|
473
|
-
basic_option(key, val)
|
|
566
|
+
basic_option(key, val, sep: sep)
|
|
474
567
|
else
|
|
475
|
-
shell_option(key, val, **kwargs)
|
|
568
|
+
shell_option(key, val, sep: sep, **kwargs)
|
|
476
569
|
end
|
|
477
570
|
true
|
|
478
571
|
end
|
|
@@ -481,24 +574,23 @@ module Squared
|
|
|
481
574
|
OptionPartition.arg?(target, *args, **kwargs)
|
|
482
575
|
end
|
|
483
576
|
|
|
484
|
-
def exist?(*args, add: false, first: false, last: false)
|
|
485
|
-
return
|
|
486
|
-
return path.join(*args).exist? unless args.empty?
|
|
577
|
+
def exist?(*args, add: false, first: false, last: false, glob: false)
|
|
578
|
+
return with_glob?(File.join(*args), glob) unless args.empty?
|
|
487
579
|
|
|
488
580
|
if first || last
|
|
489
|
-
return false unless (val = first ? self.first : self.last)
|
|
581
|
+
return false unless (val = first ? self.first : self.last)
|
|
490
582
|
|
|
491
|
-
|
|
583
|
+
with_glob?(val, glob).tap do |ret|
|
|
492
584
|
next unless add && ret
|
|
493
585
|
|
|
494
|
-
|
|
586
|
+
add_first(path: true, reverse: !first)
|
|
495
587
|
end
|
|
496
588
|
else
|
|
497
|
-
each_with_index do |val,
|
|
498
|
-
next unless
|
|
589
|
+
each_with_index do |val, i|
|
|
590
|
+
next unless with_glob?(val, glob)
|
|
499
591
|
|
|
500
592
|
if add
|
|
501
|
-
remove_at
|
|
593
|
+
remove_at i
|
|
502
594
|
add_path val
|
|
503
595
|
end
|
|
504
596
|
return true
|
|
@@ -520,6 +612,12 @@ module Squared
|
|
|
520
612
|
val[OPT_VALUE, 1] || val
|
|
521
613
|
end
|
|
522
614
|
|
|
615
|
+
def with_glob?(val, glob = true)
|
|
616
|
+
return false unless path && val.is_a?(String) && !val.empty?
|
|
617
|
+
|
|
618
|
+
path.join(val).exist? || (glob && !path.glob(val).empty?)
|
|
619
|
+
end
|
|
620
|
+
|
|
523
621
|
def windows?
|
|
524
622
|
Rake::Win32.windows?
|
|
525
623
|
end
|
|
@@ -538,31 +636,31 @@ module Squared
|
|
|
538
636
|
end
|
|
539
637
|
|
|
540
638
|
def last(val, pat)
|
|
541
|
-
(@last ||= []).
|
|
639
|
+
(@last ||= []).push([val, pat, $1]) if val =~ pat
|
|
542
640
|
self << val
|
|
543
641
|
end
|
|
544
642
|
|
|
545
643
|
def pass(&blk)
|
|
546
644
|
ret = to_a.map!(&:to_s).reject(&:empty?)
|
|
547
645
|
@last&.each do |val, pat, key|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
ret.each_with_index do |opt,
|
|
646
|
+
items = []
|
|
647
|
+
index = nil
|
|
648
|
+
ret.each_with_index do |opt, i|
|
|
551
649
|
if opt == val
|
|
552
|
-
|
|
553
|
-
elsif
|
|
554
|
-
|
|
650
|
+
index = i
|
|
651
|
+
elsif index && opt[pat, 1] == key
|
|
652
|
+
items << i
|
|
555
653
|
end
|
|
556
654
|
end
|
|
557
|
-
next unless
|
|
655
|
+
next unless index && !items.empty?
|
|
558
656
|
|
|
559
|
-
val = ret[
|
|
560
|
-
cur =
|
|
561
|
-
|
|
657
|
+
val = ret[index]
|
|
658
|
+
cur = index
|
|
659
|
+
items.each do |k|
|
|
562
660
|
ret[cur] = ret[k]
|
|
563
661
|
cur = k
|
|
564
662
|
end
|
|
565
|
-
ret[
|
|
663
|
+
ret[items.last] = val
|
|
566
664
|
end
|
|
567
665
|
return ret unless block_given?
|
|
568
666
|
|
|
@@ -3,16 +3,6 @@
|
|
|
3
3
|
module Squared
|
|
4
4
|
module Workspace
|
|
5
5
|
module Repo
|
|
6
|
-
class << self
|
|
7
|
-
def read_manifest(path)
|
|
8
|
-
require 'rexml/document'
|
|
9
|
-
return unless (file = path + '.repo/manifest.xml').exist?
|
|
10
|
-
|
|
11
|
-
doc = REXML::Document.new(file.read)
|
|
12
|
-
doc.elements['manifest/include'].attributes['name']&.sub('.xml', '')
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
6
|
attr_reader :manifest_url, :manifest
|
|
17
7
|
|
|
18
8
|
def repo(url, manifest = 'latest', run: nil, script: nil, args: nil, dev: nil, prod: nil,
|
|
@@ -25,18 +15,18 @@ module Squared
|
|
|
25
15
|
@root = nil unless path.directory?
|
|
26
16
|
elsif !@root.exist?
|
|
27
17
|
@root.mkpath
|
|
28
|
-
elsif !repo_install?
|
|
29
|
-
@root = nil
|
|
18
|
+
elsif !repo_install? && !repo_confirm
|
|
19
|
+
@root = nil
|
|
30
20
|
end
|
|
21
|
+
raise_error Errno::EEXIST, path.cleanpath, hint: 'REPO_HOME' unless @root
|
|
31
22
|
end
|
|
32
|
-
raise_error("path invalid: #{val}", hint: 'REPO_HOME') unless @root
|
|
33
23
|
path.realdirpath
|
|
34
24
|
elsif (val = env('REPO_ROOT'))
|
|
35
25
|
@root = Pathname.new(val).realdirpath
|
|
36
26
|
if !@root.exist?
|
|
37
27
|
@root.mkpath
|
|
38
|
-
elsif !repo_install?(parent: true)
|
|
39
|
-
raise_error
|
|
28
|
+
elsif !repo_install?(parent: true) && !repo_confirm
|
|
29
|
+
raise_error Errno::EEXIST, @root, hint: 'REPO_ROOT'
|
|
40
30
|
end
|
|
41
31
|
@root.join(main).realdirpath
|
|
42
32
|
elsif repo_install?(parent: true) && (!@home.exist? || @root + main == @home)
|
|
@@ -51,9 +41,13 @@ module Squared
|
|
|
51
41
|
@manifest = manifest
|
|
52
42
|
data = scriptobj
|
|
53
43
|
if repo?
|
|
44
|
+
sc, ru = env('REPO_BUILD', '').split(',', 2).map!(&:strip)
|
|
54
45
|
if script
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
data[:script] = if sc.to_s.empty?
|
|
47
|
+
script
|
|
48
|
+
else
|
|
49
|
+
data[:env][:script] = true
|
|
50
|
+
case sc
|
|
57
51
|
when 'verbose'
|
|
58
52
|
@verbose = 1
|
|
59
53
|
if script.is_a?(Array)
|
|
@@ -67,20 +61,23 @@ module Squared
|
|
|
67
61
|
@warning = false
|
|
68
62
|
script
|
|
69
63
|
else
|
|
70
|
-
|
|
64
|
+
sc
|
|
71
65
|
end
|
|
72
|
-
|
|
73
|
-
else
|
|
74
|
-
data[:script] = script
|
|
75
|
-
end
|
|
66
|
+
end
|
|
76
67
|
data[:args] = (val = env('REPO_SCRIPT')) ? shell_split(val, join: true) : args
|
|
77
|
-
|
|
78
|
-
data[:run] = val
|
|
79
|
-
data[:env] = true
|
|
68
|
+
data[:global][:script] = true
|
|
80
69
|
else
|
|
81
|
-
|
|
70
|
+
ru ||= sc
|
|
71
|
+
end
|
|
72
|
+
if run
|
|
73
|
+
data[:run] = if ru.to_s.empty?
|
|
74
|
+
run
|
|
75
|
+
else
|
|
76
|
+
data[:env][:run] = true
|
|
77
|
+
ru
|
|
78
|
+
end
|
|
79
|
+
data[:global][:run] = true
|
|
82
80
|
end
|
|
83
|
-
data[:global] = true
|
|
84
81
|
data[:dev] = env_match 'REPO_DEV', dev
|
|
85
82
|
data[:prod] = env_match 'REPO_PROD', prod
|
|
86
83
|
if (val = env('REPO_GROUP'))
|
|
@@ -98,9 +95,8 @@ module Squared
|
|
|
98
95
|
if script
|
|
99
96
|
data[:script] = script
|
|
100
97
|
data[:args] = args
|
|
101
|
-
else
|
|
102
|
-
data[:run] = run
|
|
103
98
|
end
|
|
99
|
+
data[:run] = run if run
|
|
104
100
|
data[:dev] = dev
|
|
105
101
|
data[:prod] = prod
|
|
106
102
|
script_set(data, group: group, ref: ref)
|
|
@@ -115,7 +111,7 @@ module Squared
|
|
|
115
111
|
|
|
116
112
|
namespace task_name('repo') do |ns|
|
|
117
113
|
path = ns.scope.path
|
|
118
|
-
branch = env('REPO_MANIFEST') ||
|
|
114
|
+
branch = env('REPO_MANIFEST') || repo_manifest
|
|
119
115
|
target = branch || manifest
|
|
120
116
|
stage = nil
|
|
121
117
|
opts = %w[force rebase detach submodules fail no-update gc]
|
|
@@ -160,7 +156,7 @@ module Squared
|
|
|
160
156
|
args = args.to_a
|
|
161
157
|
u = env('REPO_URL') || manifest_url
|
|
162
158
|
m = args.first && !opts.include?(args.first) ? args.shift : target
|
|
163
|
-
g = args.first && !opts.include?(args.first)
|
|
159
|
+
g = (args.shift if args.first && !opts.include?(args.first))
|
|
164
160
|
g = case (val = env('REPO_GROUPS'))
|
|
165
161
|
when '', NilClass
|
|
166
162
|
g
|
|
@@ -216,7 +212,7 @@ module Squared
|
|
|
216
212
|
end
|
|
217
213
|
end
|
|
218
214
|
|
|
219
|
-
series.sync.
|
|
215
|
+
series.sync.push(
|
|
220
216
|
task_join(path, 'all'),
|
|
221
217
|
task_join(path, 'init'),
|
|
222
218
|
task_join(path, 'sync')
|
|
@@ -224,11 +220,19 @@ module Squared
|
|
|
224
220
|
end
|
|
225
221
|
end
|
|
226
222
|
|
|
223
|
+
def repo_manifest(path = root)
|
|
224
|
+
return unless (file = path + '.repo/manifest.xml').exist?
|
|
225
|
+
|
|
226
|
+
require 'rexml/document'
|
|
227
|
+
doc = REXML::Document.new(file.read)
|
|
228
|
+
doc.elements['manifest/include'].attributes['name']&.sub('.xml', '')
|
|
229
|
+
end
|
|
230
|
+
|
|
227
231
|
def repo_confirm
|
|
228
232
|
return false unless root.directory?
|
|
229
233
|
|
|
230
234
|
path = sub_style(root, styles: theme[:inline])
|
|
231
|
-
@repo_override = Common::Prompt.confirm(
|
|
235
|
+
@repo_override = env('REPO_Y', equals: '1') || Common::Prompt.confirm(
|
|
232
236
|
"#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation?",
|
|
233
237
|
'N',
|
|
234
238
|
timeout: env('REPO_TIMEOUT', 15, ignore: '0')
|
|
@@ -247,7 +251,7 @@ module Squared
|
|
|
247
251
|
def repo_opts(*args)
|
|
248
252
|
return args unless (n = ARGV.index('--'))
|
|
249
253
|
|
|
250
|
-
ARGV[
|
|
254
|
+
ARGV[n.succ..-1].concat(args)
|
|
251
255
|
end
|
|
252
256
|
|
|
253
257
|
def repo?
|
|
@@ -199,9 +199,7 @@ module Squared
|
|
|
199
199
|
end
|
|
200
200
|
|
|
201
201
|
def batch?(obj, key)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
data.keys.any? { |ref| obj.ref?(ref) }
|
|
202
|
+
(data = batch_get(key)) ? data.keys.any? { |ref| obj.ref?(ref) } : false
|
|
205
203
|
end
|
|
206
204
|
|
|
207
205
|
def chain?(val)
|
|
@@ -240,9 +238,11 @@ module Squared
|
|
|
240
238
|
end
|
|
241
239
|
|
|
242
240
|
def already_invoked?(list, val)
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
241
|
+
if val
|
|
242
|
+
list.include?(val) && !invoked_get(val).nil?
|
|
243
|
+
else
|
|
244
|
+
Rake::Task.tasks.any? { |obj| obj.already_invoked && list.include?(obj.name) }
|
|
245
|
+
end
|
|
246
246
|
end
|
|
247
247
|
end
|
|
248
248
|
|
|
@@ -3,30 +3,9 @@
|
|
|
3
3
|
module Squared
|
|
4
4
|
module Workspace
|
|
5
5
|
module Support
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def hashlist
|
|
12
|
-
Hash.new { |data, key| data[key] = [] }
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def hashdup(data, pass: {})
|
|
16
|
-
ret = {}
|
|
17
|
-
data.each do |key, val|
|
|
18
|
-
ret[key] = case val
|
|
19
|
-
when Hash
|
|
20
|
-
pass[val] ||= hashdup(val, pass: pass)
|
|
21
|
-
when Proc, Method
|
|
22
|
-
val
|
|
23
|
-
else
|
|
24
|
-
val.dup
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
ret
|
|
28
|
-
end
|
|
29
|
-
end
|
|
6
|
+
RunData = Struct.new('RunData', :run, :block)
|
|
7
|
+
ChainData = Struct.new('ChainData', :action, :step, :with, :before, :after, :sync)
|
|
8
|
+
BannerData = Struct.new('BannerData', :command, :order, :styles, :border)
|
|
30
9
|
end
|
|
31
10
|
end
|
|
32
11
|
end
|