squared 0.5.13 → 0.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +88 -14
- 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 +70 -48
- 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 +494 -330
- data/lib/squared/workspace/project/docker.rb +375 -273
- data/lib/squared/workspace/project/git.rb +326 -310
- 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 +643 -342
- data/lib/squared/workspace/project/support/class.rb +171 -80
- 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
|
@@ -10,9 +10,9 @@ module Squared
|
|
|
10
10
|
include Common::Shell
|
|
11
11
|
extend Forwardable
|
|
12
12
|
|
|
13
|
-
OPT_NAME = /\A(?:(--)|-)((?(1)[
|
|
14
|
-
OPT_VALUE = /\A-{0,2}([
|
|
15
|
-
OPT_SINGLE = /\A-([
|
|
13
|
+
OPT_NAME = /\A(?:(--)|-)((?(1)[A-Za-z\d]+|[A-Za-z\d]))\z/
|
|
14
|
+
OPT_VALUE = /\A-{0,2}([^= ]+)(?: *= *| +)(.+)\z/
|
|
15
|
+
OPT_SINGLE = /\A-([A-Za-z\d])(.+)\z/
|
|
16
16
|
private_constant :OPT_NAME, :OPT_VALUE, :OPT_SINGLE
|
|
17
17
|
|
|
18
18
|
class << self
|
|
@@ -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,11 +29,25 @@ 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
|
-
if
|
|
35
|
-
val
|
|
36
|
-
elsif escape
|
|
50
|
+
if escape
|
|
37
51
|
shell_escape(val, quote: quote, double: double)
|
|
38
52
|
else
|
|
39
53
|
shell_quote(val, force: force, double: double)
|
|
@@ -45,13 +59,13 @@ module Squared
|
|
|
45
59
|
else
|
|
46
60
|
target.concat(ret)
|
|
47
61
|
end
|
|
48
|
-
ret
|
|
62
|
+
err || ret
|
|
49
63
|
end
|
|
50
64
|
|
|
51
65
|
def clear(target, opts, pass: true, styles: nil, **kwargs)
|
|
52
66
|
return if opts.empty?
|
|
53
67
|
|
|
54
|
-
kwargs[:subject] ||=
|
|
68
|
+
kwargs[:subject] ||= target.first.stripext
|
|
55
69
|
kwargs[:hint] ||= 'unrecognized'
|
|
56
70
|
append(target, opts, delim: true) if kwargs.delete(:append)
|
|
57
71
|
warn log_message(Logger::WARN, opts.join(', '), pass: true, **kwargs)
|
|
@@ -86,6 +100,20 @@ module Squared
|
|
|
86
100
|
ret.select { |val| single ? val.size == 1 : val.size > 1 }
|
|
87
101
|
end
|
|
88
102
|
|
|
103
|
+
def uniq!(list, pass = [])
|
|
104
|
+
keys = {}
|
|
105
|
+
list.each_with_index do |val, i|
|
|
106
|
+
j = val =~ OPT_VALUE ? $1 : val
|
|
107
|
+
(keys[j] ||= []) << i unless pass.include?(j)
|
|
108
|
+
end
|
|
109
|
+
data = keys.map { |item| item[1].size > 1 ? item[1][0..-2] : [] }.reject(&:empty?)
|
|
110
|
+
return if data.empty?
|
|
111
|
+
|
|
112
|
+
data.each { |key| key.each { |i| list[i] = nil } }
|
|
113
|
+
list.compact!
|
|
114
|
+
list
|
|
115
|
+
end
|
|
116
|
+
|
|
89
117
|
def arg?(target, *args, value: false, **)
|
|
90
118
|
r, s = args.partition { |val| val.is_a?(Regexp) }
|
|
91
119
|
r << matchopts(s, value) unless s.empty?
|
|
@@ -93,10 +121,6 @@ module Squared
|
|
|
93
121
|
r.any? { |pat| s.any?(pat) }
|
|
94
122
|
end
|
|
95
123
|
|
|
96
|
-
def opt?(val)
|
|
97
|
-
val.start_with?('-') && (OPT_NAME.match?(val) || OPT_VALUE.match?(val) || OPT_SINGLE.match?(val))
|
|
98
|
-
end
|
|
99
|
-
|
|
100
124
|
def pattern?(val)
|
|
101
125
|
val.match?(/(?:\A\^|\$\z)/) || val.match?(/(?:\.[*+]|\(\?:|\\[dsw]|\[.+\]|\{\d+,?\d*\})/)
|
|
102
126
|
end
|
|
@@ -126,13 +150,12 @@ module Squared
|
|
|
126
150
|
end
|
|
127
151
|
end
|
|
128
152
|
|
|
129
|
-
attr_reader :target, :extras, :found, :errors, :values, :project, :path
|
|
153
|
+
attr_reader :target, :extras, :found, :errors, :values, :project, :path, :sep
|
|
130
154
|
|
|
131
155
|
def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
|
|
132
156
|
: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
|
|
157
|
+
def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :shift, :unshift,
|
|
158
|
+
:pop, :push, :concat, :index, :join, :map, :map!, :detect, :select, :select!, :reject, :size
|
|
136
159
|
|
|
137
160
|
def_delegator :@extras, :delete, :remove
|
|
138
161
|
def_delegator :@extras, :delete_at, :remove_at
|
|
@@ -140,10 +163,11 @@ module Squared
|
|
|
140
163
|
def_delegator :@extras, :find_all, :detect_all
|
|
141
164
|
def_delegator :@extras, :find_index, :detect_index
|
|
142
165
|
|
|
143
|
-
def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
|
|
166
|
+
def initialize(opts, list, target = Set.new, project: nil, path: nil, sep: '=', **kwargs, &blk)
|
|
144
167
|
@target = target.is_a?(Set) ? target : target.to_set
|
|
145
168
|
@project = project
|
|
146
169
|
@path = path || project&.path
|
|
170
|
+
@sep = sep
|
|
147
171
|
@errors = []
|
|
148
172
|
@found = []
|
|
149
173
|
parse(list, opts, **kwargs, &blk)
|
|
@@ -177,7 +201,7 @@ module Squared
|
|
|
177
201
|
.each do |val|
|
|
178
202
|
if (n = val.index('='))
|
|
179
203
|
flag = val[0, n]
|
|
180
|
-
case val[n
|
|
204
|
+
case val[n.succ]
|
|
181
205
|
when 'e'
|
|
182
206
|
e << flag
|
|
183
207
|
when 'b'
|
|
@@ -202,7 +226,7 @@ module Squared
|
|
|
202
226
|
else
|
|
203
227
|
next
|
|
204
228
|
end
|
|
205
|
-
m << flag if
|
|
229
|
+
m << flag if val[n + 2] == 'm'
|
|
206
230
|
bare << flag if val.end_with?('?')
|
|
207
231
|
else
|
|
208
232
|
bare << val
|
|
@@ -211,7 +235,7 @@ module Squared
|
|
|
211
235
|
no = (no || []).map { |val| (n = val.index('=')) ? val[0, n] : val }
|
|
212
236
|
bare.concat(no)
|
|
213
237
|
if underscore
|
|
214
|
-
tr = ->(
|
|
238
|
+
tr = ->(a) { a.map { |val| val.tr('-', '_') } }
|
|
215
239
|
@values.concat(tr.call(@values))
|
|
216
240
|
bare.concat(tr.call(bare))
|
|
217
241
|
e.concat(tr.call(e))
|
|
@@ -231,7 +255,7 @@ module Squared
|
|
|
231
255
|
[f, /\A\d*(?:\.\d+)?\z/],
|
|
232
256
|
[si, /\A-?\d+\z/]
|
|
233
257
|
].freeze
|
|
234
|
-
numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) &&
|
|
258
|
+
numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) && v.match?(pat) } }
|
|
235
259
|
skip = false
|
|
236
260
|
opts.each do |opt|
|
|
237
261
|
next skip = true if opt == '--'
|
|
@@ -249,21 +273,21 @@ module Squared
|
|
|
249
273
|
val = $2
|
|
250
274
|
merge = m.include?(key)
|
|
251
275
|
if e.include?(key)
|
|
252
|
-
add shell_option(key, val, merge: merge)
|
|
276
|
+
add shell_option(key, val, merge: merge, sep: sep)
|
|
253
277
|
elsif q.include?(key)
|
|
254
|
-
add quote_option(key, val, double: qq.include?(key), merge: merge)
|
|
278
|
+
add quote_option(key, val, double: qq.include?(key), merge: merge, sep: sep)
|
|
255
279
|
elsif p.include?(key)
|
|
256
280
|
if val.match?(/\A(["']).+\1\z/)
|
|
257
|
-
add shell_option(key, val, escape: false, merge: merge)
|
|
281
|
+
add shell_option(key, val, escape: false, merge: merge, sep: sep)
|
|
258
282
|
elsif path
|
|
259
|
-
add quote_option(key, path + val, merge: merge)
|
|
283
|
+
add quote_option(key, path + val, merge: merge, sep: sep)
|
|
260
284
|
else
|
|
261
285
|
push opt
|
|
262
286
|
end
|
|
263
287
|
elsif b.include?(key) || (bl.include?(key) && %w[true false].include?(val)) || numcheck.call(key, val)
|
|
264
|
-
add basic_option(key, val, merge: merge)
|
|
288
|
+
add basic_option(key, val, merge: merge, sep: sep)
|
|
265
289
|
elsif merge
|
|
266
|
-
add basic_option(key, val, merge: true)
|
|
290
|
+
add basic_option(key, val, merge: true, sep: sep)
|
|
267
291
|
else
|
|
268
292
|
push opt
|
|
269
293
|
end
|
|
@@ -275,28 +299,33 @@ module Squared
|
|
|
275
299
|
skip = true if first&.any? { |s| s.is_a?(Regexp) ? opt.match?(s) : !opt.include?(s) }
|
|
276
300
|
end
|
|
277
301
|
end
|
|
278
|
-
@values = @values.empty? ? /\A\s+\z/ : /\A(#{@values.join('|')})
|
|
302
|
+
@values = @values.empty? ? /\A\s+\z/ : /\A(#{@values.join('|')})#{sep}(.+)\z/m
|
|
279
303
|
@extras.each_with_index(&blk) if block_given?
|
|
280
304
|
self
|
|
281
305
|
end
|
|
282
306
|
|
|
283
|
-
def swap(opts = nil)
|
|
307
|
+
def swap(opts = nil, &blk)
|
|
284
308
|
unless opts
|
|
285
309
|
opts = found
|
|
286
310
|
@found = []
|
|
287
311
|
end
|
|
312
|
+
opts.sort!(&blk) if block_given?
|
|
288
313
|
@extras = opts
|
|
289
314
|
self
|
|
290
315
|
end
|
|
291
316
|
|
|
292
|
-
def append(*args, **kwargs)
|
|
317
|
+
def append(*args, **kwargs, &blk)
|
|
293
318
|
args = extras if args.empty?
|
|
294
|
-
OptionPartition.append(target, *args, **kwargs)
|
|
319
|
+
out = OptionPartition.append(target, *args, **kwargs, &blk)
|
|
320
|
+
errors.concat(out) if out && (block_given? || kwargs[:filter])
|
|
295
321
|
self
|
|
296
322
|
end
|
|
297
323
|
|
|
298
324
|
def append_any(*args, quote: true, **kwargs)
|
|
299
325
|
(args.empty? ? extras : args.flatten).each do |val|
|
|
326
|
+
val = yield val if block_given?
|
|
327
|
+
next unless val.is_a?(String)
|
|
328
|
+
|
|
300
329
|
if exist?(val)
|
|
301
330
|
add_path(val, **kwargs)
|
|
302
331
|
elsif quote
|
|
@@ -314,7 +343,7 @@ module Squared
|
|
|
314
343
|
end
|
|
315
344
|
|
|
316
345
|
def values_of(*args, strict: true, first: false, last: false)
|
|
317
|
-
eq, s = strict ? [
|
|
346
|
+
eq, s = strict ? [sep, '[^ ]+'] : ['(?:=| +)', '[^-][^ ]*']
|
|
318
347
|
g = ["\"((?:[^\"]|(?<=\\\\)\"(?!$#{windows? ? '| ' : ''}))*)\""]
|
|
319
348
|
g << "'((?:[^']|'\\\\'')*)'" unless windows?
|
|
320
349
|
g << "(#{s})"
|
|
@@ -353,22 +382,18 @@ module Squared
|
|
|
353
382
|
def clear(opts = nil, errors: false, **kwargs)
|
|
354
383
|
styles = project.theme[:inline] if project
|
|
355
384
|
if errors
|
|
356
|
-
OptionPartition.clear(target,
|
|
357
|
-
|
|
385
|
+
OptionPartition.clear(target, @errors, styles: styles, **kwargs)
|
|
386
|
+
@errors.clear
|
|
358
387
|
return self unless opts
|
|
359
388
|
end
|
|
360
389
|
opts ||= extras
|
|
361
|
-
OptionPartition.clear(target,
|
|
362
|
-
opts
|
|
363
|
-
else
|
|
364
|
-
opts.reject { |val| found.include?(val) }
|
|
365
|
-
end, styles: styles, **kwargs)
|
|
390
|
+
OptionPartition.clear(target, opts - found, styles: styles, **kwargs)
|
|
366
391
|
opts.clear
|
|
367
392
|
self
|
|
368
393
|
end
|
|
369
394
|
|
|
370
395
|
def adjoin(*args, with: nil, start: false)
|
|
371
|
-
|
|
396
|
+
index = -1
|
|
372
397
|
temp = to_a
|
|
373
398
|
if with
|
|
374
399
|
pat = case with
|
|
@@ -379,53 +404,114 @@ module Squared
|
|
|
379
404
|
else
|
|
380
405
|
with
|
|
381
406
|
end
|
|
382
|
-
temp.each_with_index do |val,
|
|
407
|
+
temp.each_with_index do |val, i|
|
|
383
408
|
if val.to_s.match?(pat)
|
|
384
|
-
|
|
409
|
+
index = i + (start.is_a?(Numeric) ? start : 1)
|
|
385
410
|
break
|
|
386
411
|
end
|
|
387
412
|
end
|
|
388
413
|
else
|
|
389
|
-
temp.each_with_index do |val,
|
|
390
|
-
if
|
|
414
|
+
temp.each_with_index do |val, i|
|
|
415
|
+
if index == 0
|
|
391
416
|
next unless val.start_with?('-')
|
|
392
417
|
|
|
393
|
-
|
|
418
|
+
index = i
|
|
394
419
|
break
|
|
395
|
-
elsif
|
|
420
|
+
elsif i > 0 && !val.start_with?('-')
|
|
396
421
|
if start
|
|
397
|
-
|
|
422
|
+
index = i + (start.is_a?(Numeric) ? start : 1)
|
|
398
423
|
break
|
|
399
424
|
end
|
|
400
|
-
|
|
425
|
+
index = 0
|
|
401
426
|
end
|
|
402
427
|
end
|
|
403
428
|
end
|
|
404
|
-
if
|
|
429
|
+
if index > 0
|
|
405
430
|
if args.empty?
|
|
406
431
|
args = dup
|
|
407
432
|
reset
|
|
408
433
|
else
|
|
409
434
|
args.each { |val| remove val }
|
|
410
435
|
end
|
|
411
|
-
args = temp[0...
|
|
436
|
+
args = temp[0...index] + args + temp[index..-1]
|
|
412
437
|
target.clear
|
|
413
438
|
end
|
|
414
439
|
merge args
|
|
415
440
|
self
|
|
416
441
|
end
|
|
417
442
|
|
|
418
|
-
def add_path(*args, **kwargs)
|
|
419
|
-
|
|
443
|
+
def add_path(*args, force: true, double: false, **kwargs)
|
|
444
|
+
if args.empty?
|
|
445
|
+
args = select { |s| s.is_a?(String) }
|
|
446
|
+
args.map! { |val| path + val } if path
|
|
447
|
+
append(args, force: force, **kwargs)
|
|
448
|
+
else
|
|
449
|
+
add shell_quote(path ? path.join(*args) : File.join(*args), option: false, force: force, double: double)
|
|
450
|
+
end
|
|
420
451
|
self
|
|
421
452
|
end
|
|
422
453
|
|
|
423
454
|
def add_quote(*args, **kwargs)
|
|
424
|
-
args.compact!
|
|
425
|
-
|
|
455
|
+
merge(args.compact.map! { |val| val == '--' ? val : shell_quote(val, **kwargs) })
|
|
456
|
+
self
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
def add_option(flag, val = nil, **kwargs)
|
|
460
|
+
add shell_option(flag, val, **kwargs)
|
|
461
|
+
self
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
def add_first(fallback = nil, prefix: nil, path: false, quote: false, reverse: false, expect: false, **kwargs)
|
|
465
|
+
val = (reverse ? pop : shift) || fallback
|
|
466
|
+
if val
|
|
467
|
+
val.delete_prefix!(prefix) if prefix
|
|
468
|
+
return self if block_given? && !(val = yield val).is_a?(String)
|
|
469
|
+
|
|
470
|
+
if path
|
|
471
|
+
add_path(val, **kwargs)
|
|
472
|
+
elsif quote
|
|
473
|
+
add_quote(val, **kwargs)
|
|
474
|
+
else
|
|
475
|
+
add val
|
|
476
|
+
end
|
|
477
|
+
elsif expect
|
|
478
|
+
raise(expect.is_a?(String) ? expect : 'no value provided')
|
|
479
|
+
end
|
|
426
480
|
self
|
|
427
481
|
end
|
|
428
482
|
|
|
483
|
+
def last(val = nil, &blk)
|
|
484
|
+
unless block_given?
|
|
485
|
+
case val
|
|
486
|
+
when NilClass
|
|
487
|
+
return extras.last
|
|
488
|
+
when Numeric
|
|
489
|
+
return extras.last(val)
|
|
490
|
+
when String, Array, Regexp
|
|
491
|
+
val = OptionPartition.send(:matchopts, val) unless val.is_a?(Regexp)
|
|
492
|
+
blk = proc { |s| s&.match?(val) }
|
|
493
|
+
else
|
|
494
|
+
raise TypeError, "unknown: #{val}"
|
|
495
|
+
end
|
|
496
|
+
end
|
|
497
|
+
ret = find_all(&blk)
|
|
498
|
+
unless ret.empty?
|
|
499
|
+
ret = case val
|
|
500
|
+
when NilClass
|
|
501
|
+
ret.first(1)
|
|
502
|
+
when Numeric
|
|
503
|
+
ret.first(val)
|
|
504
|
+
else
|
|
505
|
+
ret
|
|
506
|
+
end
|
|
507
|
+
ret.each do |opt|
|
|
508
|
+
delete opt
|
|
509
|
+
add opt
|
|
510
|
+
end
|
|
511
|
+
end
|
|
512
|
+
val.nil? ? ret.first : ret
|
|
513
|
+
end
|
|
514
|
+
|
|
429
515
|
def splice(*exclude, quote: true, delim: true, path: false, pattern: false, &blk)
|
|
430
516
|
found, other = if block_given?
|
|
431
517
|
partition(&blk)
|
|
@@ -459,7 +545,7 @@ module Squared
|
|
|
459
545
|
self
|
|
460
546
|
end
|
|
461
547
|
|
|
462
|
-
def append?(key, val = nil, type: nil, force: false, **kwargs)
|
|
548
|
+
def append?(key, val = nil, type: nil, force: false, sep: '=', **kwargs)
|
|
463
549
|
return false unless force || !arg?(key)
|
|
464
550
|
|
|
465
551
|
val = yield self if block_given?
|
|
@@ -468,11 +554,11 @@ module Squared
|
|
|
468
554
|
type ||= :quote if kwargs.empty?
|
|
469
555
|
add case type
|
|
470
556
|
when :quote
|
|
471
|
-
quote_option(key, val)
|
|
557
|
+
quote_option(key, val, sep: sep)
|
|
472
558
|
when :basic
|
|
473
|
-
basic_option(key, val)
|
|
559
|
+
basic_option(key, val, sep: sep)
|
|
474
560
|
else
|
|
475
|
-
shell_option(key, val, **kwargs)
|
|
561
|
+
shell_option(key, val, sep: sep, **kwargs)
|
|
476
562
|
end
|
|
477
563
|
true
|
|
478
564
|
end
|
|
@@ -481,24 +567,23 @@ module Squared
|
|
|
481
567
|
OptionPartition.arg?(target, *args, **kwargs)
|
|
482
568
|
end
|
|
483
569
|
|
|
484
|
-
def exist?(*args, add: false, first: false, last: false)
|
|
485
|
-
return
|
|
486
|
-
return path.join(*args).exist? unless args.empty?
|
|
570
|
+
def exist?(*args, add: false, first: false, last: false, glob: false)
|
|
571
|
+
return with_glob?(File.join(*args), glob) unless args.empty?
|
|
487
572
|
|
|
488
573
|
if first || last
|
|
489
|
-
return false unless (val = first ? self.first : self.last)
|
|
574
|
+
return false unless (val = first ? self.first : self.last)
|
|
490
575
|
|
|
491
|
-
|
|
576
|
+
with_glob?(val, glob).tap do |ret|
|
|
492
577
|
next unless add && ret
|
|
493
578
|
|
|
494
|
-
|
|
579
|
+
add_first(path: true, reverse: !first)
|
|
495
580
|
end
|
|
496
581
|
else
|
|
497
|
-
each_with_index do |val,
|
|
498
|
-
next unless
|
|
582
|
+
each_with_index do |val, i|
|
|
583
|
+
next unless with_glob?(val, glob)
|
|
499
584
|
|
|
500
585
|
if add
|
|
501
|
-
remove_at
|
|
586
|
+
remove_at i
|
|
502
587
|
add_path val
|
|
503
588
|
end
|
|
504
589
|
return true
|
|
@@ -520,6 +605,12 @@ module Squared
|
|
|
520
605
|
val[OPT_VALUE, 1] || val
|
|
521
606
|
end
|
|
522
607
|
|
|
608
|
+
def with_glob?(val, glob = true)
|
|
609
|
+
return false unless path && val.is_a?(String) && !val.empty?
|
|
610
|
+
|
|
611
|
+
path.join(val).exist? || (glob && !path.glob(val).empty?)
|
|
612
|
+
end
|
|
613
|
+
|
|
523
614
|
def windows?
|
|
524
615
|
Rake::Win32.windows?
|
|
525
616
|
end
|
|
@@ -538,31 +629,31 @@ module Squared
|
|
|
538
629
|
end
|
|
539
630
|
|
|
540
631
|
def last(val, pat)
|
|
541
|
-
(@last ||= []).
|
|
632
|
+
(@last ||= []).push([val, pat, $1]) if val =~ pat
|
|
542
633
|
self << val
|
|
543
634
|
end
|
|
544
635
|
|
|
545
636
|
def pass(&blk)
|
|
546
637
|
ret = to_a.map!(&:to_s).reject(&:empty?)
|
|
547
638
|
@last&.each do |val, pat, key|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
ret.each_with_index do |opt,
|
|
639
|
+
items = []
|
|
640
|
+
index = nil
|
|
641
|
+
ret.each_with_index do |opt, i|
|
|
551
642
|
if opt == val
|
|
552
|
-
|
|
553
|
-
elsif
|
|
554
|
-
|
|
643
|
+
index = i
|
|
644
|
+
elsif index && opt[pat, 1] == key
|
|
645
|
+
items << i
|
|
555
646
|
end
|
|
556
647
|
end
|
|
557
|
-
next unless
|
|
648
|
+
next unless index && !items.empty?
|
|
558
649
|
|
|
559
|
-
val = ret[
|
|
560
|
-
cur =
|
|
561
|
-
|
|
650
|
+
val = ret[index]
|
|
651
|
+
cur = index
|
|
652
|
+
items.each do |k|
|
|
562
653
|
ret[cur] = ret[k]
|
|
563
654
|
cur = k
|
|
564
655
|
end
|
|
565
|
-
ret[
|
|
656
|
+
ret[items.last] = val
|
|
566
657
|
end
|
|
567
658
|
return ret unless block_given?
|
|
568
659
|
|
|
@@ -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
|
|