squared 0.4.15 → 0.4.16
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 +29 -0
- data/README.ruby.md +4 -2
- data/lib/squared/common/prompt.rb +3 -3
- data/lib/squared/common/shell.rb +1 -2
- data/lib/squared/common/utils.rb +9 -0
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +14 -10
- data/lib/squared/workspace/project/base.rb +157 -113
- data/lib/squared/workspace/project/docker.rb +21 -23
- data/lib/squared/workspace/project/git.rb +25 -27
- data/lib/squared/workspace/project/node.rb +67 -25
- data/lib/squared/workspace/project/python.rb +12 -8
- data/lib/squared/workspace/project/ruby.rb +80 -47
- data/lib/squared/workspace/project/support/class.rb +2 -4
- data/lib/squared/workspace/series.rb +4 -4
- data/lib/squared/workspace/support/base.rb +17 -0
- data/lib/squared/workspace/support.rb +1 -0
- data/lib/squared/workspace.rb +0 -8
- data/squared.gemspec +2 -2
- metadata +3 -2
@@ -19,7 +19,7 @@ module Squared
|
|
19
19
|
include ::Comparable
|
20
20
|
|
21
21
|
VAR_SET = %i[parent global script index envname desc dependfile dependindex theme archive env dev prod graph
|
22
|
-
pass exclude].freeze
|
22
|
+
pass only exclude].freeze
|
23
23
|
BLK_SET = %i[run depend doc lint test copy clean].freeze
|
24
24
|
SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+)(\S+)?)?\b/.freeze
|
25
25
|
URI_SCHEME = %r{^([a-z][a-z\d+-.]*)://[^@:\[\]\\^<>|\s]}i.freeze
|
@@ -73,8 +73,8 @@ module Squared
|
|
73
73
|
'unpack' => %i[zip tar gem ext].freeze
|
74
74
|
})
|
75
75
|
|
76
|
-
attr_reader :name, :project, :workspace, :path, :theme, :
|
77
|
-
:
|
76
|
+
attr_reader :name, :project, :workspace, :path, :theme, :group, :parent, :dependfile,
|
77
|
+
:exception, :pipe, :verbose
|
78
78
|
|
79
79
|
def initialize(workspace, path, name, *, group: nil, first: {}, last: {}, error: {}, common: ARG[:COMMON],
|
80
80
|
**kwargs)
|
@@ -89,27 +89,24 @@ module Squared
|
|
89
89
|
@test = kwargs[:test]
|
90
90
|
@copy = kwargs[:copy]
|
91
91
|
@clean = kwargs[:clean]
|
92
|
-
@version = kwargs[:version]
|
93
92
|
@release = kwargs[:release]
|
93
|
+
self.version = kwargs[:version]
|
94
|
+
self.exception = kwargs[:exception]
|
95
|
+
self.pipe = kwargs[:pipe]
|
96
|
+
self.verbose = kwargs[:verbose]
|
94
97
|
@output = []
|
95
98
|
@ref = []
|
96
99
|
@children = []
|
97
|
-
@events = {
|
98
|
-
first: first,
|
99
|
-
last: last,
|
100
|
-
error: error
|
101
|
-
}
|
100
|
+
@events = hashobj.update({ first: first, last: last, error: error })
|
102
101
|
@envname = env_key(@name).freeze
|
103
102
|
@desc = (@name.include?(':') ? @name.split(':').join(ARG[:SPACE]) : @name).freeze
|
104
103
|
@parent = nil
|
105
104
|
@global = false
|
106
105
|
@index = -1
|
107
106
|
run_set(kwargs[:run], kwargs[:env], opts: kwargs.fetch(:opts, true))
|
108
|
-
exception_set kwargs[:exception]
|
109
|
-
pipe_set kwargs[:pipe]
|
110
|
-
verbose_set kwargs[:verbose]
|
111
107
|
graph_set kwargs[:graph]
|
112
108
|
pass_set kwargs[:pass]
|
109
|
+
only_set kwargs[:only]
|
113
110
|
exclude_set kwargs[:exclude]
|
114
111
|
archive_set kwargs[:archive]
|
115
112
|
theme_set common
|
@@ -171,9 +168,7 @@ module Squared
|
|
171
168
|
def initialize_events(ref, **)
|
172
169
|
return unless (events = @workspace.events_get(group: @group, ref: ref))
|
173
170
|
|
174
|
-
events.each
|
175
|
-
data.each { |ev, blk| (@events[ev] ||= {})[task] ||= [blk] }
|
176
|
-
end
|
171
|
+
events.each { |task, data| data.each { |ev, blk| @events[ev][task] ||= [blk] } }
|
177
172
|
end
|
178
173
|
|
179
174
|
def initialize_logger(log: nil, **)
|
@@ -279,6 +274,29 @@ module Squared
|
|
279
274
|
nil
|
280
275
|
end
|
281
276
|
|
277
|
+
def version=(val)
|
278
|
+
@version = val&.to_s
|
279
|
+
end
|
280
|
+
|
281
|
+
def exception=(val)
|
282
|
+
@exception = env_bool(val, workspace.exception, strict: true)
|
283
|
+
end
|
284
|
+
|
285
|
+
def pipe=(val)
|
286
|
+
@pipe = env_pipe(val, workspace.pipe, strict: true)
|
287
|
+
end
|
288
|
+
|
289
|
+
def verbose=(val)
|
290
|
+
@verbose = case val
|
291
|
+
when NilClass
|
292
|
+
workspace.verbose
|
293
|
+
when String
|
294
|
+
env_bool(val, workspace.verbose, strict: true, index: true)
|
295
|
+
else
|
296
|
+
val
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
282
300
|
def ref
|
283
301
|
Base.ref
|
284
302
|
end
|
@@ -289,7 +307,7 @@ module Squared
|
|
289
307
|
|
290
308
|
namespace name do
|
291
309
|
Base.subtasks do |action, flags|
|
292
|
-
next if
|
310
|
+
next if task_pass?(action)
|
293
311
|
|
294
312
|
namespace action do
|
295
313
|
flags.each do |flag|
|
@@ -504,11 +522,9 @@ module Squared
|
|
504
522
|
if proj.respond_to?(meth.to_sym)
|
505
523
|
begin
|
506
524
|
proj.__send__(meth, sync: sync)
|
507
|
-
rescue StandardError => e
|
508
|
-
ret = on(:error, :prereqs, e)
|
509
|
-
raise unless ret == true
|
510
|
-
else
|
511
525
|
next
|
526
|
+
rescue StandardError => e
|
527
|
+
on_error(:prereqs, e, exception: true)
|
512
528
|
end
|
513
529
|
end
|
514
530
|
warn log_message(Logger::WARN, name, 'method not found', subject: 'prereqs', hint: meth)
|
@@ -561,9 +577,7 @@ module Squared
|
|
561
577
|
begin
|
562
578
|
@clean.each { |cmd, opts| build(cmd.to_s, opts, sync: sync) }
|
563
579
|
rescue StandardError => e
|
564
|
-
|
565
|
-
ret = on(:error, from, e)
|
566
|
-
raise if exception && ret != true
|
580
|
+
on_error e, from
|
567
581
|
end
|
568
582
|
else
|
569
583
|
if @clean.is_a?(Enumerable) && !series?(@clean)
|
@@ -612,8 +626,7 @@ module Squared
|
|
612
626
|
end
|
613
627
|
ret = graph_branch(self, data, tasks, out, sync: sync, pass: pass)
|
614
628
|
rescue StandardError => e
|
615
|
-
|
616
|
-
raise unless ret == true
|
629
|
+
on_error(:graph, e, exception: true)
|
617
630
|
else
|
618
631
|
if out
|
619
632
|
[out, ret]
|
@@ -622,12 +635,13 @@ module Squared
|
|
622
635
|
end
|
623
636
|
end
|
624
637
|
|
625
|
-
def unpack(target, uri
|
638
|
+
def unpack(target, file = nil, uri: nil, sync: true, digest: nil, ext: nil, force: false, depth: 1, headers: {},
|
639
|
+
verbose: self.verbose, from: :unpack)
|
626
640
|
if !target.exist?
|
627
641
|
target.mkpath
|
628
642
|
elsif !target.directory?
|
629
643
|
raise_error('invalid location', hint: target)
|
630
|
-
elsif !target.empty?
|
644
|
+
elsif !file && !target.empty?
|
631
645
|
raise_error('directory not empty', hint: target) unless force || env('UNPACK_FORCE')
|
632
646
|
create = true
|
633
647
|
end
|
@@ -654,44 +668,52 @@ module Squared
|
|
654
668
|
if (val = env('HEADERS')) && (val = parse_json(val, hint: "HEADERS_#{@envname}"))
|
655
669
|
headers = headers.is_a?(Hash) ? headers.merge(val) : val
|
656
670
|
end
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
671
|
+
if file
|
672
|
+
ext ||= File.extname(file)[1..-1]
|
673
|
+
else
|
674
|
+
data = nil
|
675
|
+
(uri = Array(uri)).each_with_index do |url, index|
|
676
|
+
fetch_uri(url, headers) do |f|
|
677
|
+
data = f.read
|
678
|
+
if algo && algo.hexdigest(data) != digest
|
679
|
+
data = nil
|
680
|
+
raise_error("checksum failed: #{digest}", hint: url) if index == uri.size - 1
|
681
|
+
end
|
682
|
+
next if ext && index == 0
|
683
|
+
|
684
|
+
case f.content_type
|
685
|
+
when 'application/zip'
|
686
|
+
ext = 'zip'
|
687
|
+
when 'application/x-gzip'
|
688
|
+
ext = 'tgz'
|
689
|
+
when 'application/x-xz'
|
690
|
+
ext = 'txz'
|
691
|
+
end
|
674
692
|
end
|
693
|
+
break uri = url if data
|
694
|
+
end
|
695
|
+
unless data && (ext ||= URI.parse(uri).path[/\.(\w+)(?:\?|\z)/, 1])
|
696
|
+
raise_error("no content#{data ? ' type' : ''}", hint: uri)
|
675
697
|
end
|
676
|
-
break uri = url if data
|
677
|
-
end
|
678
|
-
unless data && (ext ||= URI.parse(uri).path[/\.(\w+)(?:\?|\z)/, 1])
|
679
|
-
raise_error("no content#{data ? ' type' : ''}", hint: uri)
|
680
698
|
end
|
681
699
|
ext = ext.downcase
|
682
700
|
if (val = env("#{%w[zip 7z gem].include?(ext) ? ext.upcase : 'TAR'}_DEPTH", ignore: false))
|
683
701
|
depth = val.to_i
|
684
702
|
end
|
685
703
|
begin
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
704
|
+
unless file
|
705
|
+
if ext == 'gem'
|
706
|
+
dir = Dir.mktmpdir
|
707
|
+
file = File.new(File.join(dir, File.basename(uri)), 'w')
|
708
|
+
else
|
709
|
+
require 'tempfile'
|
710
|
+
file = Tempfile.new("#{name}-")
|
711
|
+
end
|
712
|
+
file.write(data)
|
713
|
+
file.close
|
714
|
+
file = Pathname.new(file)
|
715
|
+
delete = true
|
692
716
|
end
|
693
|
-
file.write(data)
|
694
|
-
file.close
|
695
717
|
if create
|
696
718
|
warn log_message(Logger::WARN, 'force remove', subject: name, hint: target)
|
697
719
|
target.rmtree
|
@@ -699,7 +721,7 @@ module Squared
|
|
699
721
|
end
|
700
722
|
case ext
|
701
723
|
when 'zip', 'aar'
|
702
|
-
session 'unzip', shell_quote(file
|
724
|
+
session 'unzip', shell_quote(file), quote_option('d', target)
|
703
725
|
when 'tar', 'tgz', 'tar.gz', 'tar.xz', 'gz', 'xz'
|
704
726
|
flags = +(verbose ? 'v' : '')
|
705
727
|
if ext.end_with?('gz')
|
@@ -707,24 +729,24 @@ module Squared
|
|
707
729
|
elsif ext.end_with?('xz')
|
708
730
|
flags += 'J'
|
709
731
|
end
|
710
|
-
session 'tar', "-x#{flags}", basic_option('strip-components', depth), quote_option('f', file
|
732
|
+
session 'tar', "-x#{flags}", basic_option('strip-components', depth), quote_option('f', file),
|
711
733
|
quote_option('C', target)
|
712
734
|
depth = 0
|
713
735
|
when '7z'
|
714
|
-
session '7z', 'x', shell_quote(file
|
736
|
+
session '7z', 'x', shell_quote(file), "-o#{shell_quote(target)}"
|
715
737
|
when 'gem'
|
716
|
-
session 'gem', 'unpack', shell_quote(file
|
738
|
+
session 'gem', 'unpack', shell_quote(file), quote_option('target', target)
|
717
739
|
depth = 0 unless val
|
718
740
|
else
|
719
|
-
raise_error("unsupported format: #{ext}", hint: uri)
|
741
|
+
raise_error("unsupported format: #{ext}", hint: uri || file)
|
720
742
|
end
|
721
|
-
run(sync: sync, from: from)
|
743
|
+
run(sync: sync, banner: verbose, from: from)
|
722
744
|
while depth > 0 && target.children.size == 1
|
723
745
|
entry = target.children.first
|
724
746
|
break unless entry.directory?
|
725
747
|
|
726
748
|
i = 0
|
727
|
-
while (dest = target + "#{File.basename(file
|
749
|
+
while (dest = target + "#{File.basename(file)}-#{i}").exist?
|
728
750
|
i += 1
|
729
751
|
end
|
730
752
|
FileUtils.mv(entry, dest)
|
@@ -736,8 +758,8 @@ module Squared
|
|
736
758
|
ensure
|
737
759
|
if dir
|
738
760
|
remove_entry dir
|
739
|
-
|
740
|
-
file
|
761
|
+
elsif delete && file&.exist?
|
762
|
+
file.unlink
|
741
763
|
end
|
742
764
|
end
|
743
765
|
end
|
@@ -755,7 +777,7 @@ module Squared
|
|
755
777
|
end
|
756
778
|
|
757
779
|
def event(name, key, *args, override: false, **kwargs, &blk)
|
758
|
-
data = @events[name.to_sym]
|
780
|
+
data = @events[name.to_sym]
|
759
781
|
items = if override
|
760
782
|
data[key.to_sym] = []
|
761
783
|
else
|
@@ -802,6 +824,8 @@ module Squared
|
|
802
824
|
graph_set val
|
803
825
|
when :pass
|
804
826
|
pass_set val
|
827
|
+
when :only
|
828
|
+
only_set val
|
805
829
|
when :exclude
|
806
830
|
exclude_set val
|
807
831
|
when :parent
|
@@ -969,11 +993,11 @@ module Squared
|
|
969
993
|
puts_oe(*args, pipe: pipe)
|
970
994
|
end
|
971
995
|
|
972
|
-
def run(cmd = @session, var = nil, exception:
|
996
|
+
def run(cmd = @session, var = nil, exception: self.exception, sync: true, from: nil, banner: true, chdir: path,
|
973
997
|
interactive: nil, **)
|
974
998
|
unless cmd
|
975
|
-
|
976
|
-
return
|
999
|
+
warn log_message(Logger::WARN, 'no command given', subject: project, hint: from || 'unknown', pass: true)
|
1000
|
+
return
|
977
1001
|
end
|
978
1002
|
i = interactive && !(@session && option('y'))
|
979
1003
|
cmd = cmd.target if cmd.is_a?(OptionPartition)
|
@@ -988,7 +1012,7 @@ module Squared
|
|
988
1012
|
['Run', 'Y']
|
989
1013
|
end
|
990
1014
|
unless confirm("#{title}? [#{sub_style(cmd, styles: theme[:inline])}] #{y == 'Y' ? '[Y/n]' : '[y/N]'} ", y)
|
991
|
-
|
1015
|
+
exit 1
|
992
1016
|
end
|
993
1017
|
end
|
994
1018
|
log&.info cmd
|
@@ -1013,10 +1037,7 @@ module Squared
|
|
1013
1037
|
ret = shell(*args, chdir: chdir, exception: exception)
|
1014
1038
|
end
|
1015
1039
|
rescue StandardError => e
|
1016
|
-
|
1017
|
-
ret = on(:error, from, e)
|
1018
|
-
raise unless ret == true
|
1019
|
-
|
1040
|
+
on_error(from, e, exception: true)
|
1020
1041
|
false
|
1021
1042
|
else
|
1022
1043
|
on :last, from
|
@@ -1029,7 +1050,7 @@ module Squared
|
|
1029
1050
|
begin
|
1030
1051
|
cmd.flatten.each { |val| run(val, env, sync: sync, banner: banner, **kwargs) }
|
1031
1052
|
rescue StandardError => e
|
1032
|
-
ret = on
|
1053
|
+
ret = on :error, from, e
|
1033
1054
|
raise unless ret == true
|
1034
1055
|
end
|
1035
1056
|
on :last, from
|
@@ -1276,6 +1297,10 @@ module Squared
|
|
1276
1297
|
puts 'Success'
|
1277
1298
|
end
|
1278
1299
|
|
1300
|
+
def print_error(err, loglevel: Logger::WARN, pass: false)
|
1301
|
+
warn log_message(loglevel, err, pass: pass) if warning?
|
1302
|
+
end
|
1303
|
+
|
1279
1304
|
def print_item(*val)
|
1280
1305
|
puts unless printfirst?
|
1281
1306
|
printsucc
|
@@ -1318,7 +1343,7 @@ module Squared
|
|
1318
1343
|
ret.join("\n")
|
1319
1344
|
end
|
1320
1345
|
|
1321
|
-
def print_status(*args, from: nil)
|
1346
|
+
def print_status(*args, from: nil, **kwargs)
|
1322
1347
|
return if stdin?
|
1323
1348
|
|
1324
1349
|
case from
|
@@ -1327,6 +1352,12 @@ module Squared
|
|
1327
1352
|
out[1] = sub_style(out[1], pat: /^( +major )(\d+)(.+)$/, styles: theme[:major], index: 2)
|
1328
1353
|
out[1] = sub_style(out[1], pat: /^(.+)(minor )(\d+)(.+)$/, styles: theme[:active], index: 3)
|
1329
1354
|
puts out
|
1355
|
+
when :completed
|
1356
|
+
if verbose && kwargs[:start]
|
1357
|
+
msg = sub_style('completed', styles: theme[:active])
|
1358
|
+
puts log_message(Logger::INFO, *args, msg, subject: kwargs[:subject],
|
1359
|
+
hint: time_format(epochtime - kwargs[:start]))
|
1360
|
+
end
|
1330
1361
|
end
|
1331
1362
|
end
|
1332
1363
|
|
@@ -1619,13 +1650,9 @@ module Squared
|
|
1619
1650
|
multiple: false, force: true, **kwargs)
|
1620
1651
|
puts if !series && !printfirst?
|
1621
1652
|
msg = "#{msg} (optional)" unless force
|
1622
|
-
unless (ret = choice(msg, list, multiple: multiple, force: force, **kwargs))
|
1623
|
-
|
1624
|
-
|
1625
|
-
if ret.nil? || ret.empty?
|
1626
|
-
return unless force
|
1627
|
-
|
1628
|
-
exit 1
|
1653
|
+
unless (ret = choice(msg, list, multiple: multiple, force: force, **kwargs)) && !ret.empty?
|
1654
|
+
exit 1 if force
|
1655
|
+
return
|
1629
1656
|
end
|
1630
1657
|
ret = multiple ? ret.map! { |val| val.sub(trim, '') } : ret.sub(trim, '') if trim
|
1631
1658
|
if column
|
@@ -1671,8 +1698,8 @@ module Squared
|
|
1671
1698
|
ret
|
1672
1699
|
end
|
1673
1700
|
|
1674
|
-
def command_args(args, force: false, **kwargs)
|
1675
|
-
return
|
1701
|
+
def command_args(args, min: 0, force: false, **kwargs)
|
1702
|
+
return if args.size > min || option('i', 'interactive', **kwargs, equals: '0')
|
1676
1703
|
|
1677
1704
|
readline('Enter arguments', force: force)
|
1678
1705
|
end
|
@@ -1734,6 +1761,21 @@ module Squared
|
|
1734
1761
|
fill ? semver(ret) : ret
|
1735
1762
|
end
|
1736
1763
|
|
1764
|
+
def semcmp(val, other)
|
1765
|
+
a, b = [val, other].map! { |ver| ver.match(SEM_VER) }
|
1766
|
+
return 1 unless a
|
1767
|
+
return -1 unless b
|
1768
|
+
return 0 if a[0] == b[0]
|
1769
|
+
|
1770
|
+
a, b = [a, b].map! { |c| [c[1], c[3], c[5] || '0'] }
|
1771
|
+
a.each_with_index do |c, index|
|
1772
|
+
next if c == (d = b[index])
|
1773
|
+
|
1774
|
+
return c.to_i < d.to_i ? 1 : -1
|
1775
|
+
end
|
1776
|
+
0
|
1777
|
+
end
|
1778
|
+
|
1737
1779
|
def indexitem(val)
|
1738
1780
|
[$1.to_i, $2 && $2[1..-1]] if val =~ /\A[=^#{indexchar}](\d+)(:.+)?\z/
|
1739
1781
|
end
|
@@ -1775,9 +1817,9 @@ module Squared
|
|
1775
1817
|
end
|
1776
1818
|
|
1777
1819
|
def on(event, from, *args, **kwargs)
|
1778
|
-
return unless from &&
|
1820
|
+
return unless from && @events.key?(event)
|
1779
1821
|
|
1780
|
-
|
1822
|
+
@events[event][from]&.each do |obj|
|
1781
1823
|
target, opts = if obj.is_a?(Array) && obj[1].is_a?(Hash)
|
1782
1824
|
[obj[0], kwargs.empty? ? obj[1] : obj[1].merge(kwargs)]
|
1783
1825
|
else
|
@@ -1794,12 +1836,21 @@ module Squared
|
|
1794
1836
|
end
|
1795
1837
|
end
|
1796
1838
|
|
1839
|
+
def on_error(err, from, exception: self.exception, pass: false, dryrun: false)
|
1840
|
+
log&.error err
|
1841
|
+
unless dryrun
|
1842
|
+
ret = on :error, from, err
|
1843
|
+
raise err if exception && ret != true
|
1844
|
+
end
|
1845
|
+
print_error(err, pass: pass) unless ret
|
1846
|
+
end
|
1847
|
+
|
1797
1848
|
def pwd_set(done = nil, pass: false, from: nil, dryrun: false)
|
1798
1849
|
pwd = Pathname.pwd
|
1799
1850
|
if block_given?
|
1800
1851
|
begin
|
1801
1852
|
pass = semscan(pass).join <= RUBY_VERSION if pass.is_a?(String)
|
1802
|
-
if (path == pwd || pass == true) && !workspace.
|
1853
|
+
if (path == pwd || pass == true) && (workspace.mri? || !workspace.windows?)
|
1803
1854
|
ret = yield
|
1804
1855
|
else
|
1805
1856
|
Dir.chdir(path)
|
@@ -1807,11 +1858,7 @@ module Squared
|
|
1807
1858
|
Dir.chdir(pwd)
|
1808
1859
|
end
|
1809
1860
|
rescue StandardError => e
|
1810
|
-
|
1811
|
-
unless dryrun
|
1812
|
-
ret = on(:error, from, e)
|
1813
|
-
raise if exception && ret != true
|
1814
|
-
end
|
1861
|
+
on_error(e, from, dryrun: dryrun)
|
1815
1862
|
else
|
1816
1863
|
ret
|
1817
1864
|
end
|
@@ -1900,25 +1947,6 @@ module Squared
|
|
1900
1947
|
@parent = val if val.is_a?(Project::Base)
|
1901
1948
|
end
|
1902
1949
|
|
1903
|
-
def exception_set(val)
|
1904
|
-
@exception = env_bool(val, workspace.exception, strict: true)
|
1905
|
-
end
|
1906
|
-
|
1907
|
-
def pipe_set(val)
|
1908
|
-
@pipe = env_pipe(val, workspace.pipe, strict: true)
|
1909
|
-
end
|
1910
|
-
|
1911
|
-
def verbose_set(val)
|
1912
|
-
@verbose = case val
|
1913
|
-
when NilClass
|
1914
|
-
workspace.verbose
|
1915
|
-
when String
|
1916
|
-
env_bool(val, workspace.verbose, strict: true, index: true)
|
1917
|
-
else
|
1918
|
-
val
|
1919
|
-
end
|
1920
|
-
end
|
1921
|
-
|
1922
1950
|
def graph_set(val)
|
1923
1951
|
@graph = if val
|
1924
1952
|
Array(val).map { |s| workspace.prefix ? workspace.task_name(s).to_sym : s.to_sym }.freeze
|
@@ -1926,7 +1954,11 @@ module Squared
|
|
1926
1954
|
end
|
1927
1955
|
|
1928
1956
|
def pass_set(val)
|
1929
|
-
@pass = (val
|
1957
|
+
@pass = Array(val).freeze
|
1958
|
+
end
|
1959
|
+
|
1960
|
+
def only_set(val)
|
1961
|
+
@only = val && as_a(val, :to_s).freeze
|
1930
1962
|
end
|
1931
1963
|
|
1932
1964
|
def exclude_set(val)
|
@@ -1985,6 +2017,10 @@ module Squared
|
|
1985
2017
|
end
|
1986
2018
|
end
|
1987
2019
|
|
2020
|
+
def task_pass?(key)
|
2021
|
+
@only ? !@only.include?(key) : @pass.include?(key)
|
2022
|
+
end
|
2023
|
+
|
1988
2024
|
def projectpath?(val)
|
1989
2025
|
val = Pathname.new(val).cleanpath
|
1990
2026
|
val.absolute? ? val.to_s.start_with?(File.join(path, '')) : !val.to_s.start_with?(File.join('..', ''))
|
@@ -2086,6 +2122,14 @@ module Squared
|
|
2086
2122
|
BLK_SET
|
2087
2123
|
end
|
2088
2124
|
|
2125
|
+
def hashobj
|
2126
|
+
Workspace::Support.hashobj
|
2127
|
+
end
|
2128
|
+
|
2129
|
+
def hashlist
|
2130
|
+
Workspace::Support.hashlist
|
2131
|
+
end
|
2132
|
+
|
2089
2133
|
def borderstyle
|
2090
2134
|
((data = workspace.banner_get(*@ref, group: group)) && data[:border]) || theme[:border]
|
2091
2135
|
end
|
@@ -94,6 +94,7 @@ module Squared
|
|
94
94
|
subtasks({
|
95
95
|
'build' => %i[tag context bake].freeze,
|
96
96
|
'compose' => %i[build run exec up].freeze,
|
97
|
+
'bake' => %i[build check].freeze,
|
97
98
|
'image' => %i[list rm push tag save].freeze,
|
98
99
|
'container' => %i[run create exec update commit inspect diff start stop restart pause unpause top stats kill
|
99
100
|
rm].freeze,
|
@@ -128,12 +129,12 @@ module Squared
|
|
128
129
|
|
129
130
|
namespace name do
|
130
131
|
Docker.subtasks do |action, flags|
|
131
|
-
next if
|
132
|
+
next if task_pass?(action)
|
132
133
|
|
133
134
|
namespace action do
|
134
135
|
flags.each do |flag|
|
135
136
|
case action
|
136
|
-
when 'build'
|
137
|
+
when 'build', 'bake'
|
137
138
|
case flag
|
138
139
|
when :tag, :context
|
139
140
|
format_desc(action, flag, 'opts*', before: flag == :tag ? 'name' : 'dir')
|
@@ -141,16 +142,26 @@ module Squared
|
|
141
142
|
param = param_guard(action, flag, args: args, key: flag)
|
142
143
|
buildx(:build, args.extras, "#{flag}": param)
|
143
144
|
end
|
144
|
-
when :bake
|
145
|
+
when :bake, :build
|
146
|
+
next unless bake?
|
147
|
+
|
145
148
|
format_desc action, flag, ':?,opts*,target*,context?'
|
146
149
|
task flag do |_, args|
|
147
150
|
args = args.to_a
|
148
151
|
if args.first == ':'
|
149
152
|
choice_command :bake
|
150
153
|
else
|
151
|
-
buildx
|
154
|
+
buildx :bake, args
|
152
155
|
end
|
153
156
|
end
|
157
|
+
when :check
|
158
|
+
next unless bake?
|
159
|
+
|
160
|
+
format_desc action, flag, 'target'
|
161
|
+
task flag, [:target] do |_, args|
|
162
|
+
target = param_guard(action, flag, args: args, key: :target)
|
163
|
+
buildx :bake, ['allow=fs.read=*', 'call=check', target]
|
164
|
+
end
|
154
165
|
end
|
155
166
|
when 'compose'
|
156
167
|
case flag
|
@@ -307,7 +318,7 @@ module Squared
|
|
307
318
|
op.parse(OPT_DOCKER[:buildx][flag == :bake ? :bake : :build] + OPT_DOCKER[:buildx][:shared])
|
308
319
|
case flag
|
309
320
|
when :build, :context
|
310
|
-
append_tag(tag || option('tag', ignore: false) ||
|
321
|
+
append_tag(tag || option('tag', ignore: false) || self.tag)
|
311
322
|
append_context context
|
312
323
|
when :bake
|
313
324
|
unless op.empty?
|
@@ -317,7 +328,7 @@ module Squared
|
|
317
328
|
if projectpath?(val = args.pop)
|
318
329
|
context = val
|
319
330
|
else
|
320
|
-
op.
|
331
|
+
op.push(val)
|
321
332
|
end
|
322
333
|
end
|
323
334
|
op.append(args, escape: true)
|
@@ -573,12 +584,7 @@ module Squared
|
|
573
584
|
case flag
|
574
585
|
when :run
|
575
586
|
unless session_arg?('name', target: target)
|
576
|
-
target << basic_option('name', dnsname("#{name}_%s" %
|
577
|
-
require 'random/formatter'
|
578
|
-
Random.new.alphanumeric(6)
|
579
|
-
else
|
580
|
-
(0...6).map { rand(97..122).chr }.join
|
581
|
-
end))
|
587
|
+
target << basic_option('name', dnsname("#{name}_%s" % rand_s(6)))
|
582
588
|
end
|
583
589
|
when :exec
|
584
590
|
raise_error('no command args', hint: from) if list.empty?
|
@@ -679,11 +685,7 @@ module Squared
|
|
679
685
|
puts log_message(Logger::INFO, 'none detected', subject: "#{name}:#{from}", hint: hint) if found || y
|
680
686
|
end
|
681
687
|
rescue StandardError => e
|
682
|
-
|
683
|
-
ret = on(:error, from, e)
|
684
|
-
raise if exception && ret != true
|
685
|
-
|
686
|
-
warn log_message(Logger::WARN, e, pass: true) if warning?
|
688
|
+
on_error e, from
|
687
689
|
end
|
688
690
|
|
689
691
|
def confirm_command(*args, title: nil, target: nil, as: nil)
|
@@ -740,7 +742,7 @@ module Squared
|
|
740
742
|
cmd = docker_output ctx
|
741
743
|
case flag
|
742
744
|
when :tag
|
743
|
-
args = tagjoin @registry,
|
745
|
+
args = tagjoin @registry, tag
|
744
746
|
when :save
|
745
747
|
opts = "#{opts}.tar" unless opts.end_with?('.tar')
|
746
748
|
cmd << quote_option('output', File.expand_path(opts))
|
@@ -751,11 +753,7 @@ module Squared
|
|
751
753
|
else
|
752
754
|
cmd << opts << '--'
|
753
755
|
end
|
754
|
-
cmd.merge(
|
755
|
-
out.map! { |val| parse.call(val) }
|
756
|
-
else
|
757
|
-
[parse.call(out)]
|
758
|
-
end)
|
756
|
+
cmd.merge(Array(out).map! { |val| parse.call(val) })
|
759
757
|
cmd << args
|
760
758
|
print_success if success?(run(cmd)) && ctx.match?(/\A(?:network|tag|save)/)
|
761
759
|
end
|