squared 0.5.3 → 0.5.4
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 +38 -0
- data/README.ruby.md +17 -13
- data/lib/squared/common/shell.rb +8 -3
- data/lib/squared/common/system.rb +3 -3
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +11 -6
- data/lib/squared/workspace/project/base.rb +52 -35
- data/lib/squared/workspace/project/docker.rb +68 -52
- data/lib/squared/workspace/project/git.rb +213 -129
- data/lib/squared/workspace/project/node.rb +25 -14
- data/lib/squared/workspace/project/python.rb +40 -11
- data/lib/squared/workspace/project/ruby.rb +27 -19
- data/lib/squared/workspace/project/support/class.rb +64 -13
- data/lib/squared/workspace/repo.rb +47 -43
- metadata +2 -2
@@ -98,7 +98,7 @@ module Squared
|
|
98
98
|
'pack' => nil
|
99
99
|
})
|
100
100
|
|
101
|
-
def initialize(*, **kwargs)
|
101
|
+
def initialize(*, init: nil, **kwargs)
|
102
102
|
super
|
103
103
|
if @pass.include?(Node.ref)
|
104
104
|
initialize_ref Node.ref
|
@@ -108,7 +108,7 @@ module Squared
|
|
108
108
|
initialize_env(**kwargs)
|
109
109
|
end
|
110
110
|
@dependfile = @path + 'package.json'
|
111
|
-
@pm = {}
|
111
|
+
@pm = { __: init }
|
112
112
|
end
|
113
113
|
|
114
114
|
def ref
|
@@ -117,7 +117,7 @@ module Squared
|
|
117
117
|
|
118
118
|
def populate(*, **)
|
119
119
|
super
|
120
|
-
return unless outdated? && ref?(Node.ref)
|
120
|
+
return unless (outdated? && ref?(Node.ref)) || @only
|
121
121
|
|
122
122
|
namespace name do
|
123
123
|
Node.subtasks do |action, flags|
|
@@ -129,10 +129,7 @@ module Squared
|
|
129
129
|
format_desc action, nil, 'save?=prod|dev|optional|peer,name+'
|
130
130
|
task action, [:save] do |_, args|
|
131
131
|
save = param_guard(action, 'save', args: args, key: :save)
|
132
|
-
if save.
|
133
|
-
exact = true
|
134
|
-
save = save[1..-1]
|
135
|
-
end
|
132
|
+
exact = true if save.delete_prefix!('=')
|
136
133
|
case save
|
137
134
|
when 'prod', 'dev', 'optional', 'peer'
|
138
135
|
packages = args.extras
|
@@ -441,7 +438,19 @@ module Squared
|
|
441
438
|
workspace.rev_clear(name, sync: sync)
|
442
439
|
return update if !flag && env('NODE_UPDATE')
|
443
440
|
|
444
|
-
|
441
|
+
pnpm = pnpm?
|
442
|
+
yarn = pnpm ? 0 : dependtype(:yarn)
|
443
|
+
if @pm[:__] && !pnpm && yarn == 0
|
444
|
+
case @pm[:__]
|
445
|
+
when 'pnpm'
|
446
|
+
pnpm = true
|
447
|
+
when 'yarn'
|
448
|
+
yarn = 1
|
449
|
+
when 'berry'
|
450
|
+
yarn = 2
|
451
|
+
end
|
452
|
+
end
|
453
|
+
if yarn > 0
|
445
454
|
cmd = session 'yarn'
|
446
455
|
if flag == :add
|
447
456
|
cmd << 'add'
|
@@ -451,7 +460,7 @@ module Squared
|
|
451
460
|
cmd << 'install'
|
452
461
|
cmd << '--ignore-engines' if yarn == 1 && !option('ignore-engines', equals: '0')
|
453
462
|
end
|
454
|
-
elsif pnpm
|
463
|
+
elsif pnpm
|
455
464
|
cmd = session 'pnpm'
|
456
465
|
if flag == :add
|
457
466
|
cmd << 'add' << "--save-#{save}"
|
@@ -496,7 +505,7 @@ module Squared
|
|
496
505
|
banner = format_banner(cmd.temp(dryrun ? '--dry-run' : nil))
|
497
506
|
print_item banner if sync
|
498
507
|
begin
|
499
|
-
data = pwd_set { `#{cmd.temp('--json', '--loglevel=error')}` }
|
508
|
+
data = pwd_set(dryrun: dryrun) { `#{cmd.temp('--json', '--loglevel=error')}` }
|
500
509
|
doc = dependfile.read
|
501
510
|
json = JSON.parse(doc)
|
502
511
|
rescue StandardError => e
|
@@ -660,7 +669,7 @@ module Squared
|
|
660
669
|
cmd << basic_option('otp', otp) if otp ||= option('otp')
|
661
670
|
cmd << basic_option('tag', tag) if tag ||= option('tag')
|
662
671
|
cmd << basic_option('access', access) if access ||= option('access')
|
663
|
-
dryrun
|
672
|
+
dryrun ||= dryrun?('npm')
|
664
673
|
if dryrun
|
665
674
|
cmd << '--dry-run'
|
666
675
|
else
|
@@ -671,7 +680,7 @@ module Squared
|
|
671
680
|
run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(npmname, styles: theme[:active])}")
|
672
681
|
else
|
673
682
|
on :first, from
|
674
|
-
pwd_set(from: from) do
|
683
|
+
pwd_set(from: from, dryrun: dryrun) do
|
675
684
|
require 'open3'
|
676
685
|
banner = format_banner cmd.to_s
|
677
686
|
Open3.popen2e(cmd.done) do |_, out|
|
@@ -748,21 +757,23 @@ module Squared
|
|
748
757
|
when :major
|
749
758
|
if seg[0] != '0' || seg[2].nil?
|
750
759
|
seg[0] = seg[0].succ
|
760
|
+
seg[2] = '0'
|
751
761
|
else
|
752
762
|
seg[2] = seg[2].succ
|
753
763
|
end
|
764
|
+
seg[4] = '0'
|
754
765
|
when :minor
|
755
766
|
if seg[0] == '0'
|
756
767
|
seg[4] &&= seg[4].succ
|
757
768
|
else
|
758
769
|
seg[2] = seg[2].succ
|
759
770
|
end
|
771
|
+
seg[4] = '0'
|
760
772
|
when :patch
|
761
773
|
seg[4] &&= seg[4].succ
|
762
774
|
end
|
763
775
|
return if (val = seg.join) == cur
|
764
776
|
end
|
765
|
-
|
766
777
|
begin
|
767
778
|
doc = dependfile.read
|
768
779
|
if doc.sub!(/"version"\s*:\s*"#{cur}"/, "\"version\": \"#{val}\"")
|
@@ -951,7 +962,7 @@ module Squared
|
|
951
962
|
else
|
952
963
|
if key
|
953
964
|
@pm[key]
|
954
|
-
elsif (ret = @pm[:_]) && !
|
965
|
+
elsif (ret = @pm[:_]) && (!version || semgte?(ret[(ret.index('@') + 1)..-1], version))
|
955
966
|
ret
|
956
967
|
end
|
957
968
|
end
|
@@ -87,7 +87,6 @@ module Squared
|
|
87
87
|
initialize_build(Python.ref, **kwargs)
|
88
88
|
initialize_env(**kwargs)
|
89
89
|
end
|
90
|
-
@verbose = verbose.size if verbose.is_a?(String) && verbose.match?(/\Av+\z/)
|
91
90
|
dependfile_set DEP_PYTHON
|
92
91
|
editable_set editable
|
93
92
|
venv_set kwargs[:venv]
|
@@ -95,7 +94,7 @@ module Squared
|
|
95
94
|
|
96
95
|
subtasks({
|
97
96
|
'venv' => %i[exec create remove show].freeze,
|
98
|
-
'pip' => %i[uninstall freeze].freeze,
|
97
|
+
'pip' => %i[upgrade uninstall freeze].freeze,
|
99
98
|
'install' => %i[user force upgrade target editable].freeze,
|
100
99
|
'outdated' => %i[major minor patch].freeze,
|
101
100
|
'build' => %i[python poetry pdm hatch].freeze,
|
@@ -104,13 +103,22 @@ module Squared
|
|
104
103
|
'exec' => nil
|
105
104
|
})
|
106
105
|
|
106
|
+
def verbose=(val)
|
107
|
+
case val
|
108
|
+
when /\Av+\z/
|
109
|
+
@verbose = val.size
|
110
|
+
else
|
111
|
+
super
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
107
115
|
def ref
|
108
116
|
Python.ref
|
109
117
|
end
|
110
118
|
|
111
119
|
def populate(*, **)
|
112
120
|
super
|
113
|
-
return unless outdated? && ref?(Python.ref)
|
121
|
+
return unless (outdated? && ref?(Python.ref)) || @only
|
114
122
|
|
115
123
|
namespace name do
|
116
124
|
Python.subtasks do |action, flags|
|
@@ -159,7 +167,7 @@ module Squared
|
|
159
167
|
found |= 1
|
160
168
|
run(pdm_session('run', val), from: :run)
|
161
169
|
else
|
162
|
-
raise_error
|
170
|
+
raise_error "script: #{val}" if exception
|
163
171
|
found |= 2
|
164
172
|
log.warn "run script \"#{val}\" (not indexed)"
|
165
173
|
end
|
@@ -234,6 +242,14 @@ module Squared
|
|
234
242
|
end
|
235
243
|
when 'pip'
|
236
244
|
case flag
|
245
|
+
when :upgrade
|
246
|
+
format_desc action, flag, 'opts*'
|
247
|
+
task flag do |_, args|
|
248
|
+
args = args.to_a
|
249
|
+
args.prepend('upgrade')
|
250
|
+
args.append('pip')
|
251
|
+
install flag, args
|
252
|
+
end
|
237
253
|
when :freeze
|
238
254
|
format_desc action, flag, "file?=#{DEP_PYTHON[4]},opts*"
|
239
255
|
task flag do |_, args|
|
@@ -287,7 +303,7 @@ module Squared
|
|
287
303
|
when 'build'
|
288
304
|
case flag
|
289
305
|
when :poetry
|
290
|
-
next unless
|
306
|
+
next unless poetry?
|
291
307
|
when :pdm
|
292
308
|
next unless build_backend == 'pdm.backend'
|
293
309
|
when :hatch
|
@@ -325,8 +341,8 @@ module Squared
|
|
325
341
|
elsif outdated?
|
326
342
|
venv_init
|
327
343
|
workspace.rev_clear(name, sync: sync)
|
328
|
-
if !flag &&
|
329
|
-
cmd = poetry_session 'install
|
344
|
+
if !flag && poetry?
|
345
|
+
cmd = poetry_session 'install -n'
|
330
346
|
cmd << '--no-root' if option('no-root')
|
331
347
|
else
|
332
348
|
cmd = pip_session 'install'
|
@@ -351,7 +367,7 @@ module Squared
|
|
351
367
|
end
|
352
368
|
|
353
369
|
def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated'))
|
354
|
-
cmd = pip_session 'list
|
370
|
+
cmd = pip_session 'list --outdated'
|
355
371
|
append_global
|
356
372
|
cmd = session_done cmd
|
357
373
|
log.info cmd
|
@@ -458,6 +474,11 @@ module Squared
|
|
458
474
|
cmd << '--user' if user
|
459
475
|
cmd << basic_option('upgrade-strategy', strategy) if strategy
|
460
476
|
append_value out
|
477
|
+
if workspace.windows?
|
478
|
+
pip = cmd.to_a.drop(1)
|
479
|
+
cmd = python_session '-m pip'
|
480
|
+
cmd.merge(pip)
|
481
|
+
end
|
461
482
|
end
|
462
483
|
run(from: :install)
|
463
484
|
end
|
@@ -506,7 +527,7 @@ module Squared
|
|
506
527
|
end
|
507
528
|
op << basic_option('p', project) unless ENV['HATCH_PROJECT'] || op.arg?('p', 'project')
|
508
529
|
end
|
509
|
-
op
|
530
|
+
op.add_path(srcdir) if srcdir
|
510
531
|
op.clear
|
511
532
|
run(from: :"#{flag}:build")
|
512
533
|
end
|
@@ -552,7 +573,7 @@ module Squared
|
|
552
573
|
out = append_pip(nil, opts, from: flag)
|
553
574
|
case flag
|
554
575
|
when :uninstall
|
555
|
-
raise_error('no packages listed', hint:
|
576
|
+
raise_error('no packages listed', hint: flag) if out.empty?
|
556
577
|
cmd.merge(out)
|
557
578
|
when :freeze
|
558
579
|
venv_init
|
@@ -657,7 +678,7 @@ module Squared
|
|
657
678
|
end
|
658
679
|
op.swap
|
659
680
|
if edit
|
660
|
-
edit = path + edit unless %r{
|
681
|
+
edit = path + edit unless %r{\A[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
|
661
682
|
if flag == :editable
|
662
683
|
op.push(edit)
|
663
684
|
else
|
@@ -870,6 +891,14 @@ module Squared
|
|
870
891
|
puts(dir.directory? ? "Success: #{dir}" : 'Failed') if banner && !status
|
871
892
|
end
|
872
893
|
|
894
|
+
def setuptools?
|
895
|
+
build_backend ? build_backend == 'setuptools.build_meta' : dependtype == 2 || dependtype == 4
|
896
|
+
end
|
897
|
+
|
898
|
+
def poetry?
|
899
|
+
build_backend ? build_backend == 'poetry.core.masonry.api' : dependtype == 1
|
900
|
+
end
|
901
|
+
|
873
902
|
def requirements?
|
874
903
|
dependtype == 5
|
875
904
|
end
|
@@ -126,7 +126,7 @@ module Squared
|
|
126
126
|
|
127
127
|
def populate(*, **)
|
128
128
|
super
|
129
|
-
return unless outdated? && ref?(Ruby.ref)
|
129
|
+
return unless (outdated? && ref?(Ruby.ref)) || @only
|
130
130
|
|
131
131
|
namespace name do
|
132
132
|
Ruby.subtasks do |action, flags|
|
@@ -171,7 +171,7 @@ module Squared
|
|
171
171
|
format_desc action, nil, 'opts*,args*|:'
|
172
172
|
task action do |_, args|
|
173
173
|
args = args.to_a
|
174
|
-
name = basepath(
|
174
|
+
name = gemlib.any? { |file| basepath(file).join("#{gemname}.rb").exist? } ? gemname : nil
|
175
175
|
irb(name, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
|
176
176
|
end
|
177
177
|
else
|
@@ -275,7 +275,7 @@ module Squared
|
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
278
|
-
def copy(from:
|
278
|
+
def copy(from: gemlib, into: @gemdir, override: false, **kwargs)
|
279
279
|
glob = kwargs[:include]
|
280
280
|
pass = kwargs[:exclude]
|
281
281
|
if @copy && !override
|
@@ -566,7 +566,7 @@ module Squared
|
|
566
566
|
minor = 0
|
567
567
|
patch = 0
|
568
568
|
update = []
|
569
|
-
pwd_set(pass: !
|
569
|
+
pwd_set(pass: !gempwd.nil?, from: from) do
|
570
570
|
items = [[%w[Gem Current Latest], nil]]
|
571
571
|
IO.popen(cmd.done).each do |line|
|
572
572
|
if line =~ /^(\S+) \((\S+) < ([^)]+)\)$/
|
@@ -685,11 +685,11 @@ module Squared
|
|
685
685
|
on :last, from
|
686
686
|
return
|
687
687
|
when :build
|
688
|
-
if
|
689
|
-
op
|
690
|
-
|
691
|
-
|
692
|
-
|
688
|
+
if op.empty?
|
689
|
+
op.add_path(gemfile)
|
690
|
+
else
|
691
|
+
op.add_path(op.shift)
|
692
|
+
.clear(pass: false)
|
693
693
|
end
|
694
694
|
when :push
|
695
695
|
if op.empty?
|
@@ -703,7 +703,7 @@ module Squared
|
|
703
703
|
raise_error('gem not found', hint: file) unless file.exist?
|
704
704
|
raise_error("unknown args: #{op.join(', ')}", hint: flag) unless op.empty?
|
705
705
|
end
|
706
|
-
op
|
706
|
+
op.add_path(file)
|
707
707
|
run_rb(from: from, interactive: "Push #{sub_style(gemname, styles: theme[:active])}")
|
708
708
|
return
|
709
709
|
when :exec
|
@@ -730,7 +730,7 @@ module Squared
|
|
730
730
|
raise_error('missing gemname', hint: flag) if op.empty?
|
731
731
|
case flag
|
732
732
|
when :install, :uninstall, :pristine
|
733
|
-
post = readline('Enter command [args]', force: true) if flag == :install && op.
|
733
|
+
post = readline('Enter command [args]', force: true) if flag == :install && op.remove(':')
|
734
734
|
if op.arg?('all')
|
735
735
|
if flag == :pristine
|
736
736
|
append_repeat 'skip', op.extras
|
@@ -797,7 +797,7 @@ module Squared
|
|
797
797
|
run_s(args, banner: false, from: :rake)
|
798
798
|
end
|
799
799
|
|
800
|
-
def irb(name = nil, opts = [], path:
|
800
|
+
def irb(name = nil, opts = [], path: gemlib, args: nil)
|
801
801
|
op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
|
802
802
|
r = args ? [] : ['bundler/setup']
|
803
803
|
r << name if name
|
@@ -817,7 +817,6 @@ module Squared
|
|
817
817
|
|
818
818
|
begin
|
819
819
|
if (file = gemfile)
|
820
|
-
require 'rubygems'
|
821
820
|
@gemspec = Gem::Specification.load(file.to_s)
|
822
821
|
end
|
823
822
|
rescue StandardError => e
|
@@ -885,7 +884,6 @@ module Squared
|
|
885
884
|
end
|
886
885
|
end
|
887
886
|
end
|
888
|
-
require 'rubygems'
|
889
887
|
@gemdir = Pathname.new(Gem.dir) + gempath
|
890
888
|
else
|
891
889
|
parse = lambda do |path|
|
@@ -983,9 +981,9 @@ module Squared
|
|
983
981
|
|
984
982
|
def read_rakefile
|
985
983
|
@read_rakefile ||= [].tap do |ret|
|
986
|
-
|
987
|
-
pwd_set(pass: !
|
988
|
-
IO.popen(rake_output(
|
984
|
+
opt = rakepwd
|
985
|
+
pwd_set(pass: !opt.nil?) do
|
986
|
+
IO.popen(rake_output(opt, '-AT').to_s).each do |line|
|
989
987
|
next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
|
990
988
|
|
991
989
|
ret << [$1, $2]
|
@@ -1015,13 +1013,13 @@ module Squared
|
|
1015
1013
|
end
|
1016
1014
|
|
1017
1015
|
def rakepwd
|
1018
|
-
return
|
1016
|
+
return unless !pwd? && semgte?(Rake::VERSION, '13.0.4')
|
1019
1017
|
|
1020
1018
|
quote_option 'C', path
|
1021
1019
|
end
|
1022
1020
|
|
1023
1021
|
def gempwd
|
1024
|
-
return
|
1022
|
+
return unless !pwd? && semgte?(Gem::VERSION, '3.4.2')
|
1025
1023
|
|
1026
1024
|
quote_option 'C', path
|
1027
1025
|
end
|
@@ -1034,6 +1032,16 @@ module Squared
|
|
1034
1032
|
.find { |file| File.exist?(file) } || false
|
1035
1033
|
end
|
1036
1034
|
|
1035
|
+
def gemlib
|
1036
|
+
@gemlib ||= begin
|
1037
|
+
lib = Set.new(['lib'])
|
1038
|
+
if (spec = gemspec)
|
1039
|
+
lib.merge(spec.require_paths || [])
|
1040
|
+
end
|
1041
|
+
lib.select { |file| basepath(file).exist? }
|
1042
|
+
end
|
1043
|
+
end
|
1044
|
+
|
1037
1045
|
def gempath(val = version)
|
1038
1046
|
File.join('gems', "#{gemname}-#{val}")
|
1039
1047
|
end
|
@@ -45,6 +45,15 @@ module Squared
|
|
45
45
|
val.map { |s| s.sub(/\A-([a-z\d])(.+)\z/i, '\1=\2').sub(/\A--?/, '') }.reject(&:empty?)
|
46
46
|
end
|
47
47
|
|
48
|
+
def select(list, bare: true, no: true, single: false, double: false)
|
49
|
+
ret = bare ? list.grep_v(/=/) : list.grep(/=/).map! { |val| val.split('=', 2).first }
|
50
|
+
ret.map! { |val| val.split('|', 2).last }
|
51
|
+
ret = ret.grep_v(/^no-/) unless no
|
52
|
+
return ret if single == double
|
53
|
+
|
54
|
+
ret.select { |val| single ? val.size == 1 : val.size > 1 }
|
55
|
+
end
|
56
|
+
|
48
57
|
def arg?(target, *args, value: false, **)
|
49
58
|
r, s = args.partition { |val| val.is_a?(Regexp) }
|
50
59
|
unless s.empty?
|
@@ -54,15 +63,22 @@ module Squared
|
|
54
63
|
s = target.to_a.compact
|
55
64
|
r.any? { |pat| s.any?(pat) }
|
56
65
|
end
|
66
|
+
|
67
|
+
def pattern?(val)
|
68
|
+
val.match?(/(?:\A\^|\$\z)/) || val.match?(/(?:\.[*+]|\(\?:|\\[dsw]|\[.+\]|\{\d+,?\d*\})/)
|
69
|
+
end
|
57
70
|
end
|
58
71
|
|
59
72
|
attr_reader :target, :extras, :found, :errors, :values, :project, :path
|
60
73
|
|
61
74
|
def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
|
62
|
-
:merge, :delete, :delete?, :delete_if, :grep, :inspect, :to_a, :to_s
|
75
|
+
:merge, :delete, :delete?, :delete_if, :grep, :grep_v, :inspect, :to_a, :to_s
|
63
76
|
def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :last, :shift, :unshift,
|
64
77
|
:pop, :push, :index, :delete_at, :join, :map, :map!, :select, :reject, :size
|
65
78
|
|
79
|
+
def_delegator :@extras, :delete, :remove
|
80
|
+
def_delegator :@extras, :delete_if, :remove_if
|
81
|
+
|
66
82
|
def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
|
67
83
|
@target = target.is_a?(Set) ? target : target.to_set
|
68
84
|
@project = project
|
@@ -139,35 +155,35 @@ module Squared
|
|
139
155
|
skip = false
|
140
156
|
opts.each do |opt|
|
141
157
|
next skip = true if opt == '--'
|
142
|
-
next
|
158
|
+
next push opt if skip
|
143
159
|
|
144
160
|
if single&.match?(opt)
|
145
|
-
|
161
|
+
add "-#{opt}"
|
146
162
|
elsif bare.include?(opt)
|
147
|
-
|
163
|
+
add(opt.size == 1 ? "-#{opt}" : "--#{opt}")
|
148
164
|
elsif opt.start_with?('no-') && no.include?(name = opt[3..-1])
|
149
|
-
|
165
|
+
add "--no-#{name}"
|
150
166
|
else
|
151
167
|
if opt =~ /\A([^=]+)=(.+)\z/
|
152
168
|
key = $1
|
153
169
|
val = $2
|
154
170
|
merge = m.include?(key)
|
155
171
|
if e.include?(key)
|
156
|
-
|
172
|
+
add shell_option(key, val, merge: merge)
|
157
173
|
elsif q.include?(key)
|
158
|
-
|
174
|
+
add quote_option(key, val, double: qq.include?(key), merge: merge)
|
159
175
|
elsif p.include?(key) && path
|
160
|
-
|
176
|
+
add quote_option(key, path + val, merge: merge)
|
161
177
|
elsif b.include?(key) || numcheck.call(key, val)
|
162
|
-
|
178
|
+
add basic_option(key, val, merge: merge)
|
163
179
|
elsif merge
|
164
|
-
|
180
|
+
add basic_option(key, val, merge: true)
|
165
181
|
else
|
166
|
-
|
182
|
+
push opt
|
167
183
|
end
|
168
184
|
opt = key
|
169
185
|
else
|
170
|
-
|
186
|
+
push opt
|
171
187
|
skip = true if args
|
172
188
|
end
|
173
189
|
skip = true if first&.any? { |s| s.is_a?(Regexp) ? opt.match?(s) : !opt.include?(s) }
|
@@ -230,7 +246,42 @@ module Squared
|
|
230
246
|
args = items[0...i] + args + items[i..-1]
|
231
247
|
target.clear
|
232
248
|
end
|
233
|
-
merge
|
249
|
+
merge args
|
250
|
+
self
|
251
|
+
end
|
252
|
+
|
253
|
+
def add_path(*args, **kwargs)
|
254
|
+
add shell_quote(path ? path.join(*args) : File.join(*args), **kwargs)
|
255
|
+
self
|
256
|
+
end
|
257
|
+
|
258
|
+
def add_quote(*args, **kwargs)
|
259
|
+
merge(args.map { |val| shell_quote(val, **kwargs) })
|
260
|
+
self
|
261
|
+
end
|
262
|
+
|
263
|
+
def splice(*exclude, quote: true, delim: true, path: false, pattern: false, &blk)
|
264
|
+
found, other = if block_given?
|
265
|
+
partition(&blk)
|
266
|
+
elsif exclude.first.is_a?(Symbol)
|
267
|
+
partition(&exclude.first)
|
268
|
+
else
|
269
|
+
partition do |val|
|
270
|
+
next false if pattern && OptionPartition.pattern?(val)
|
271
|
+
|
272
|
+
exclude.none? { |pat| val.match?(Regexp.new(pat)) }
|
273
|
+
end
|
274
|
+
end
|
275
|
+
unless found.empty?
|
276
|
+
add '--' if delim
|
277
|
+
extras.clear
|
278
|
+
extras.concat(other)
|
279
|
+
if path
|
280
|
+
found.each { |val| add_path(val) }
|
281
|
+
else
|
282
|
+
merge(quote ? found.map! { |val| shell_quote(val) } : found)
|
283
|
+
end
|
284
|
+
end
|
234
285
|
self
|
235
286
|
end
|
236
287
|
|