squared 0.4.14 → 0.5.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 +14 -58
- data/README.md +4 -4
- data/README.ruby.md +15 -12
- data/lib/squared/common/base.rb +7 -8
- data/lib/squared/common/format.rb +3 -9
- data/lib/squared/common/prompt.rb +36 -40
- data/lib/squared/common/shell.rb +13 -8
- data/lib/squared/common/system.rb +45 -48
- data/lib/squared/common/utils.rb +3 -19
- data/lib/squared/common.rb +2 -1
- data/lib/squared/config.rb +16 -16
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +27 -40
- data/lib/squared/workspace/project/base.rb +128 -196
- data/lib/squared/workspace/project/docker.rb +37 -38
- data/lib/squared/workspace/project/git.rb +113 -139
- data/lib/squared/workspace/project/node.rb +64 -49
- data/lib/squared/workspace/project/python.rb +57 -251
- data/lib/squared/workspace/project/ruby.rb +119 -139
- data/lib/squared/workspace/project/support/class.rb +73 -34
- data/lib/squared/workspace/project.rb +0 -10
- data/lib/squared/workspace/repo.rb +6 -7
- data/lib/squared/workspace/series.rb +8 -8
- data/lib/squared/workspace/support/data.rb +3 -2
- data/lib/squared/workspace.rb +1 -1
- data/squared.gemspec +1 -1
- metadata +2 -3
- data/lib/squared/common/class.rb +0 -110
@@ -81,7 +81,7 @@ module Squared
|
|
81
81
|
'install' => %i[redownload local prefer-local].freeze,
|
82
82
|
'update' => %i[patch minor major all].freeze,
|
83
83
|
'outdated' => %i[patch minor major].freeze,
|
84
|
-
'gem' => %i[install uninstall update pristine outdated build
|
84
|
+
'gem' => %i[install uninstall update pristine outdated push build exec].freeze,
|
85
85
|
'ruby' => %i[file script version].freeze,
|
86
86
|
'exec' => nil,
|
87
87
|
'cache' => nil,
|
@@ -102,10 +102,11 @@ module Squared
|
|
102
102
|
end
|
103
103
|
dependfile_set GEMFILE
|
104
104
|
@autodetect = autodetect
|
105
|
-
|
105
|
+
@rakelist = nil
|
106
|
+
return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || (file = rakefile).nil?
|
106
107
|
|
107
108
|
begin
|
108
|
-
File.foreach(
|
109
|
+
File.foreach(file) do |line|
|
109
110
|
next unless line.match?(%r{\brequire\s+(["'])bundler/gem_tasks\1})
|
110
111
|
|
111
112
|
cmd = bundle_output('exec rake').to_s
|
@@ -134,36 +135,26 @@ module Squared
|
|
134
135
|
if flags.nil?
|
135
136
|
case action
|
136
137
|
when 'rake'
|
137
|
-
next
|
138
|
+
next unless rakefile
|
138
139
|
|
139
|
-
format_desc action, nil,
|
140
|
+
format_desc action, nil, 'tasks*,opts*|^index|#,pattern*'
|
140
141
|
task action, [:command] do |_, args|
|
141
142
|
if args.command == '#'
|
142
|
-
format_list(read_rakefile,
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
if
|
147
|
-
|
143
|
+
format_list(read_rakefile, 'rake[^N]', 'tasks', grep: args.extras, from: rakefile.to_s,
|
144
|
+
each: ->(val) { val[0] + val[1].to_s })
|
145
|
+
elsif (n, opts = indexitem(args.command))
|
146
|
+
list = read_rakefile
|
147
|
+
if (item = list[n - 1])
|
148
|
+
cmd = opts ? "#{opts} #{item.first}" : item.first
|
149
|
+
elsif exception
|
150
|
+
indexerror n, list
|
148
151
|
else
|
149
|
-
list
|
150
|
-
|
151
|
-
if (item = list[n - 1])
|
152
|
-
cmd = pre ? "#{pre} #{item.first}" : item.first
|
153
|
-
elsif exception
|
154
|
-
indexerror n, list
|
155
|
-
else
|
156
|
-
log.warn "rake task #{n} of #{list.size} (out of range)"
|
157
|
-
next
|
158
|
-
end
|
159
|
-
if opts.empty?
|
160
|
-
rake cmd
|
161
|
-
else
|
162
|
-
rake(cmd + shell_escape("[#{opts.join(',')}]"))
|
163
|
-
opts.clear
|
164
|
-
end
|
165
|
-
end
|
152
|
+
log.warn "rake task #{n} of #{list.size} (out of range)"
|
153
|
+
next
|
166
154
|
end
|
155
|
+
rake(args.extras.empty? ? cmd : cmd + shell_escape("[#{args.extras.join(',')}]"))
|
156
|
+
else
|
157
|
+
rake(opts: args.to_a)
|
167
158
|
end
|
168
159
|
end
|
169
160
|
when 'irb'
|
@@ -173,12 +164,16 @@ module Squared
|
|
173
164
|
format_desc action, nil, 'opts*,args*|:'
|
174
165
|
task action do |_, args|
|
175
166
|
args = args.to_a
|
176
|
-
|
167
|
+
if args.last == ':'
|
168
|
+
args.pop
|
169
|
+
load = readline('Enter file and arguments', force: false)
|
170
|
+
end
|
171
|
+
irb(gemname, args, load: load)
|
177
172
|
end
|
178
173
|
else
|
179
|
-
format_desc(action, nil,
|
180
|
-
|
181
|
-
|
174
|
+
format_desc(action, nil, OPT_BUNDLE[action.to_sym], after: case action
|
175
|
+
when 'cache', 'check' then nil
|
176
|
+
else 'command+' end)
|
182
177
|
task action do |_, args|
|
183
178
|
bundle(action, *args.to_a)
|
184
179
|
end
|
@@ -200,24 +195,20 @@ module Squared
|
|
200
195
|
case (filter = args.semver)
|
201
196
|
when 'major', 'minor', 'patch', 'interactive', 'i'
|
202
197
|
filter = 'interactive' if filter == 'i'
|
203
|
-
args = args.
|
198
|
+
args = args.to_a.drop(1)
|
204
199
|
else
|
205
200
|
filter = nil
|
206
201
|
args = args.to_a
|
207
202
|
end
|
208
203
|
gem!(flag, args, filter: filter)
|
209
204
|
end
|
210
|
-
when :build, :push, :exec
|
211
|
-
format_desc(action, flag, 'opts*',
|
212
|
-
when :exec then 'command,args*'
|
213
|
-
when :push then 'file?'
|
214
|
-
when :update then 'name*'
|
215
|
-
end)
|
205
|
+
when :build, :push, :exec
|
206
|
+
format_desc(action, flag, 'opts*', before: flag == :exec ? 'command,args*' : nil)
|
216
207
|
task flag do |_, args|
|
217
208
|
gem! flag, args.to_a
|
218
209
|
end
|
219
210
|
else
|
220
|
-
format_desc
|
211
|
+
format_desc action, flag, "opts*,name+#{flag == :pristine ? '|name?@version' : ''}"
|
221
212
|
task flag do |_, args|
|
222
213
|
args = param_guard(action, flag, args: args.to_a)
|
223
214
|
gem! flag, args
|
@@ -229,18 +220,19 @@ module Squared
|
|
229
220
|
format_desc action, flag, 'path,opts*,args*'
|
230
221
|
task flag, [:rb] do |_, args|
|
231
222
|
file = args.rb
|
232
|
-
args = args.
|
223
|
+
args = args.to_a.drop(1)
|
233
224
|
unless file && !file.include?('*')
|
234
|
-
|
235
|
-
|
236
|
-
|
225
|
+
values = ['Arguments']
|
226
|
+
values.prepend('Options') unless file
|
227
|
+
file, opts, extra = choice_index('Select a file', Dir.glob(file || '*.rb', base: path),
|
228
|
+
values: values, force: true, series: !args.include?('v'))
|
237
229
|
if file
|
238
|
-
|
230
|
+
extra = opts
|
239
231
|
else
|
240
232
|
args.concat(OptionPartition.strip(opts))
|
241
233
|
end
|
242
234
|
end
|
243
|
-
ruby(flag, args, file: file, args:
|
235
|
+
ruby(flag, args, file: file, args: extra)
|
244
236
|
end
|
245
237
|
when :script
|
246
238
|
format_desc action, flag, 'opts*,args*'
|
@@ -294,8 +286,8 @@ module Squared
|
|
294
286
|
on :first, :copy
|
295
287
|
dest = Pathname.new(into).realpath
|
296
288
|
print_item unless @output[0] || task_invoked?(/^copy(?::#{Ruby.ref}|$)/)
|
297
|
-
glob =
|
298
|
-
|
289
|
+
glob = as_a(glob || '**/*')
|
290
|
+
as_a(from).each_with_index do |val, i|
|
299
291
|
a = path + val
|
300
292
|
b = dest + val
|
301
293
|
c = glob[i] || glob.first
|
@@ -319,7 +311,7 @@ module Squared
|
|
319
311
|
end
|
320
312
|
log.info cmd.to_s
|
321
313
|
on :first, :outdated
|
322
|
-
banner = format_banner
|
314
|
+
banner = format_banner cmd.to_s
|
323
315
|
print_item banner if sync
|
324
316
|
pwd_set(from: :outdated) do
|
325
317
|
start = 0
|
@@ -410,7 +402,7 @@ module Squared
|
|
410
402
|
end
|
411
403
|
if found > 0
|
412
404
|
begin
|
413
|
-
if major == 0 && dependfile.read =~ /\b(?:source\s+(["'])(
|
405
|
+
if major == 0 && dependfile.read =~ /\b(?:source\s+(["'])((?~\1))\1|remote:\s+(\S+))/
|
414
406
|
status = ($2 || $3).chomp('/')
|
415
407
|
right = true
|
416
408
|
end
|
@@ -436,7 +428,7 @@ module Squared
|
|
436
428
|
def update(flag, opts = [])
|
437
429
|
bundle_session 'update', "--#{flag}"
|
438
430
|
append_bundle(opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common],
|
439
|
-
append: flag == :all ? nil : /\A
|
431
|
+
append: flag == :all ? nil : /\A[a-z\-]+=/)
|
440
432
|
run_rb(from: :update)
|
441
433
|
end
|
442
434
|
|
@@ -445,7 +437,7 @@ module Squared
|
|
445
437
|
when :file, :script
|
446
438
|
op = OptionPartition.new(opts, OPT_RUBY[:ruby], ruby_session, project: self, args: true)
|
447
439
|
if file
|
448
|
-
op.extras.
|
440
|
+
op.extras.prepend(shell_quote(path + file))
|
449
441
|
elsif command
|
450
442
|
op << quote_option('e', command, option: false)
|
451
443
|
end
|
@@ -472,8 +464,9 @@ module Squared
|
|
472
464
|
when 'rvm'
|
473
465
|
`rvm current`[/^\S+/, 0]
|
474
466
|
when 'rbenv'
|
475
|
-
|
476
|
-
|
467
|
+
`rbenv version-name`.yield_self do |name|
|
468
|
+
name.match?(SEM_VER) ? "ruby #{name}" : name
|
469
|
+
end
|
477
470
|
when 'chruby.sh'
|
478
471
|
chruby = session_output 'source', val
|
479
472
|
`#{chruby.with('ruby --version')}`
|
@@ -484,14 +477,12 @@ module Squared
|
|
484
477
|
ver = nil
|
485
478
|
`ruby --version`
|
486
479
|
end)
|
487
|
-
break if workspace.windows?
|
488
|
-
|
489
480
|
unless val.empty?
|
490
481
|
out << trim.call(case cmd
|
491
482
|
when 'chruby.sh'
|
492
483
|
`#{chruby.with('chruby --version')}`.sub(':', '')
|
493
484
|
when 'install'
|
494
|
-
"asdf #{`asdf version`.
|
485
|
+
"asdf #{`asdf version`.delete_prefix('v')}"
|
495
486
|
else
|
496
487
|
`#{cmd} --version`
|
497
488
|
end)
|
@@ -534,6 +525,8 @@ module Squared
|
|
534
525
|
case flag
|
535
526
|
when :outdated
|
536
527
|
cmd << gempwd << 'outdated'
|
528
|
+
when :push
|
529
|
+
cmd << 'push' << project
|
537
530
|
else
|
538
531
|
cmd << flag
|
539
532
|
end
|
@@ -542,9 +535,12 @@ module Squared
|
|
542
535
|
case flag
|
543
536
|
when :install, :update
|
544
537
|
list.concat(OPT_GEM[:install_base])
|
538
|
+
first = ['=']
|
539
|
+
when :uninstall, :pristine
|
540
|
+
first = ['=']
|
545
541
|
end
|
546
542
|
cmd.merge(preopts)
|
547
|
-
op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag])
|
543
|
+
op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag], first: first)
|
548
544
|
op.each do |opt|
|
549
545
|
if opt =~ op.values
|
550
546
|
case $1
|
@@ -645,8 +641,7 @@ module Squared
|
|
645
641
|
styles = %i[yellow]
|
646
642
|
pat = pat.last
|
647
643
|
end
|
648
|
-
b = b.rjust(e)
|
649
|
-
b = sub_style(b, *colormap(styles), pat: pat, index: 2)
|
644
|
+
b = sub_style(b.rjust(e), *colormap(styles), pat: pat, index: 2)
|
650
645
|
h = sub_style(c.rjust(f), styles: latest.flatten.compact, pat: pat, index: 2)
|
651
646
|
j += 1
|
652
647
|
if queue
|
@@ -664,15 +659,15 @@ module Squared
|
|
664
659
|
else
|
665
660
|
unless update.empty?
|
666
661
|
cmd = gem_output 'update', '-f'
|
667
|
-
|
662
|
+
option('document', prefix: 'gem', ignore: false) do |val|
|
668
663
|
cmd << case val
|
669
664
|
when '0', 'false'
|
670
665
|
'--no-document'
|
671
666
|
else
|
672
|
-
basic_option
|
667
|
+
basic_option 'document', val
|
673
668
|
end
|
674
669
|
end
|
675
|
-
|
670
|
+
option('user-install', prefix: 'gem', ignore: false) do |val|
|
676
671
|
cmd << case val
|
677
672
|
when '0', 'false'
|
678
673
|
'--no-user-install'
|
@@ -683,32 +678,31 @@ module Squared
|
|
683
678
|
cmd.merge(update)
|
684
679
|
run(cmd, banner: false, from: :'gem:update')
|
685
680
|
end
|
686
|
-
|
681
|
+
unless stdin?
|
682
|
+
status = print_footer("major #{major} / minor #{minor} / patch #{patch}", right: true).split("\n")
|
683
|
+
status[1] = status[1]
|
684
|
+
.yield_self do |s|
|
685
|
+
sub_style(s, pat: /^( +major )(\d+)(.+)$/, styles: theme[:major], index: 2)
|
686
|
+
end
|
687
|
+
.yield_self do |s|
|
688
|
+
sub_style(s, pat: /^(.+)(minor )(\d+)(.+)$/, styles: theme[:active], index: 3)
|
689
|
+
end
|
690
|
+
puts status
|
691
|
+
end
|
687
692
|
end
|
688
693
|
on :last, from
|
689
694
|
return
|
690
|
-
when :build
|
691
|
-
if op.empty?
|
692
|
-
|
693
|
-
|
694
|
-
else
|
695
|
-
op << shell_quote(path + op.shift)
|
696
|
-
op.clear(pass: false)
|
697
|
-
end
|
698
|
-
when :push
|
699
|
-
if op.empty?
|
700
|
-
op << shell_quote(path + choice_index('Select a file', Dir.glob('*.gem', base: path), force: true))
|
701
|
-
else
|
702
|
-
file = path + op.shift
|
703
|
-
raise_error("unknown args: #{op.join(', ')}", hint: flag) unless op.empty?
|
704
|
-
if file.exist?
|
705
|
-
op << shell_quote(file)
|
695
|
+
when :build, :push
|
696
|
+
if !op.empty?
|
697
|
+
if flag == :build && op.size == 1
|
698
|
+
op << shell_quote(path + op.first)
|
706
699
|
else
|
707
|
-
raise_error(
|
700
|
+
raise_error("unknown args: #{op.join(', ')}", hint: flag)
|
708
701
|
end
|
702
|
+
elsif flag == :build
|
703
|
+
spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *path.glob('*.gemspec')]
|
704
|
+
op << File.basename(spec) if (spec = spec.find { |file| File.exist?(file) })
|
709
705
|
end
|
710
|
-
run_rb(from: from, interactive: "Push #{sub_style(project, styles: theme[:active])}")
|
711
|
-
return
|
712
706
|
when :exec
|
713
707
|
raise_error('missing command', hint: flag) if op.empty?
|
714
708
|
op << basic_option('gem', project) unless op.arg?('g', 'gem')
|
@@ -716,43 +710,26 @@ module Squared
|
|
716
710
|
op.push(args)
|
717
711
|
end
|
718
712
|
op.append(delim: true, quote: false)
|
719
|
-
when :update
|
720
|
-
unless op.arg?('system')
|
721
|
-
op.push(project) if op.empty?
|
722
|
-
op.adjoin
|
723
|
-
end
|
724
|
-
op.clear(errors: true)
|
725
713
|
else
|
726
|
-
raise_error('missing gemname', hint: flag) if op.empty?
|
727
|
-
|
728
|
-
when :install, :uninstall, :pristine
|
729
|
-
post = readline('Enter command [args]', force: true) if flag == :install && op.extras.delete(':')
|
714
|
+
raise_error('missing gemname', hint: flag) if op.empty? && !op.arg?('system')
|
715
|
+
if flag == :pristine
|
730
716
|
if op.arg?('all')
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
elsif (n = op.extras.find_index { |val| val.match?(/(\A|[a-z])@\d/) })
|
738
|
-
items = op.extras.to_a
|
739
|
-
name = items.delete_at(n)
|
740
|
-
if (n = name.index('@')) == 0
|
741
|
-
pre = project
|
717
|
+
append_repeat 'skip', op.extras
|
718
|
+
op.extras.clear
|
719
|
+
elsif (n = op.first.index('@'))
|
720
|
+
name = op.shift
|
721
|
+
if n == 0
|
722
|
+
op << project
|
742
723
|
ver = name[1..-1]
|
743
724
|
else
|
744
|
-
|
745
|
-
ver = name[
|
725
|
+
op << shell_escape(name[0, n])
|
726
|
+
ver = name[n + 1..-1]
|
746
727
|
end
|
747
|
-
op
|
748
|
-
|
749
|
-
.reset
|
750
|
-
elsif flag != :install
|
751
|
-
op.adjoin
|
728
|
+
op << shell_option('version', ver)
|
729
|
+
op.clear
|
752
730
|
end
|
753
731
|
end
|
754
732
|
op.append.clear(errors: true)
|
755
|
-
op << '--' << post if post
|
756
733
|
end
|
757
734
|
run_rb(from: from)
|
758
735
|
end
|
@@ -793,13 +770,14 @@ module Squared
|
|
793
770
|
run_s(args, banner: false, from: :rake)
|
794
771
|
end
|
795
772
|
|
796
|
-
def irb(name, opts = [], path: @path + 'lib',
|
773
|
+
def irb(name, opts = [], path: @path + 'lib', load: nil)
|
797
774
|
op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
|
798
|
-
r =
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
775
|
+
r = as_a name
|
776
|
+
r.prepend('bundler/setup') unless load
|
777
|
+
r.each { |val| op << shell_option('r', val, merge: true) }
|
778
|
+
as_a(path).each { |val| op << quote_option('I', val, merge: true) }
|
779
|
+
if load
|
780
|
+
op << '--' << load
|
803
781
|
op.clear
|
804
782
|
else
|
805
783
|
op.append(delim: true)
|
@@ -849,14 +827,15 @@ module Squared
|
|
849
827
|
pwd_set(pass: !pwd.nil?) do
|
850
828
|
out = `#{gem_output(pwd, 'list --local -d', project)}`
|
851
829
|
if out =~ /#{Regexp.escape(project)} \(([^)]+)\)/
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
830
|
+
$1.split(/\s*,\s*/)
|
831
|
+
.prepend(@version)
|
832
|
+
.uniq
|
833
|
+
.each do |val|
|
834
|
+
next unless out =~ /\(#{Regexp.escape(val)}(?:,[^)]+|\b)\):([^\n]+)/
|
835
|
+
|
836
|
+
set.call(val, $1)
|
837
|
+
break
|
838
|
+
end
|
860
839
|
end
|
861
840
|
end
|
862
841
|
end
|
@@ -892,7 +871,7 @@ module Squared
|
|
892
871
|
private
|
893
872
|
|
894
873
|
def run_rb(**kwargs)
|
895
|
-
run(banner: !@session
|
874
|
+
run(banner: !@session.include?('--quiet'), **kwargs)
|
896
875
|
end
|
897
876
|
|
898
877
|
def append_bundle(opts, list, target: @session, append: nil)
|
@@ -954,16 +933,18 @@ module Squared
|
|
954
933
|
end
|
955
934
|
|
956
935
|
def read_rakefile
|
957
|
-
@
|
958
|
-
pwd = rakepwd
|
959
|
-
pwd_set(pass: !pwd.nil?) do
|
960
|
-
IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
|
961
|
-
next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
|
936
|
+
return @rakelist if @rakelist
|
962
937
|
|
963
|
-
|
964
|
-
|
938
|
+
ret = []
|
939
|
+
pwd = rakepwd
|
940
|
+
pwd_set(pass: !pwd.nil?) do
|
941
|
+
IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
|
942
|
+
next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
|
943
|
+
|
944
|
+
ret << [$1, $2]
|
965
945
|
end
|
966
946
|
end
|
947
|
+
@rakelist = ret
|
967
948
|
end
|
968
949
|
|
969
950
|
def preopts
|
@@ -979,20 +960,19 @@ module Squared
|
|
979
960
|
end
|
980
961
|
|
981
962
|
def rakefile
|
982
|
-
return
|
963
|
+
return unless (file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? })
|
983
964
|
|
984
|
-
|
985
|
-
@rakefile = file ? path + file : ''
|
965
|
+
path + file
|
986
966
|
end
|
987
967
|
|
988
968
|
def rakepwd
|
989
|
-
return
|
969
|
+
return unless Rake::VERSION >= '13.0.4'
|
990
970
|
|
991
971
|
quote_option 'C', path
|
992
972
|
end
|
993
973
|
|
994
974
|
def gempwd
|
995
|
-
return
|
975
|
+
return unless Gem::VERSION >= '3.4.2'
|
996
976
|
|
997
977
|
quote_option 'C', path
|
998
978
|
end
|
@@ -31,7 +31,7 @@ module Squared
|
|
31
31
|
def clear(target, opts, pass: true, styles: nil, **kwargs)
|
32
32
|
return if opts.empty?
|
33
33
|
|
34
|
-
kwargs[:subject] ||= stripext
|
34
|
+
kwargs[:subject] ||= stripext target.first
|
35
35
|
kwargs[:hint] ||= 'unrecognized'
|
36
36
|
append(target, opts, delim: true) if kwargs.delete(:append)
|
37
37
|
warn log_message(Logger::WARN, opts.join(', '), pass: true, **kwargs)
|
@@ -50,10 +50,11 @@ module Squared
|
|
50
50
|
def arg?(target, *args, value: false, **)
|
51
51
|
r, s = args.partition { |val| val.is_a?(Regexp) }
|
52
52
|
unless s.empty?
|
53
|
-
s.map! { |val| Regexp.escape(shell_option(val)) }
|
53
|
+
s.map! { |val| Regexp.escape(val.start_with?('-') ? val : shell_option(val)) }
|
54
54
|
r << /\A(?:#{s.join('|')})#{value ? '[ =].' : '(?: |=|\z)'}/
|
55
55
|
end
|
56
|
-
|
56
|
+
s = target.to_a.compact
|
57
|
+
r.any? { |pat| s.any?(pat) }
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
@@ -65,7 +66,7 @@ module Squared
|
|
65
66
|
:pop, :push, :join, :map, :map!, :select, :reject, :size
|
66
67
|
|
67
68
|
def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
|
68
|
-
@target = target.is_a?(Set) ? target :
|
69
|
+
@target = target.is_a?(Set) ? target : target.to_set
|
69
70
|
@project = project
|
70
71
|
@path = path || project&.path
|
71
72
|
@errors = []
|
@@ -139,7 +140,6 @@ module Squared
|
|
139
140
|
numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) && pat.match?(v) } }
|
140
141
|
skip = false
|
141
142
|
opts.each do |opt|
|
142
|
-
next skip = true if opt == '--'
|
143
143
|
next @extras << opt if skip
|
144
144
|
|
145
145
|
if single&.match?(opt)
|
@@ -189,8 +189,7 @@ module Squared
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def append(*args, **kwargs)
|
192
|
-
args
|
193
|
-
OptionPartition.append(target, *args, **kwargs)
|
192
|
+
OptionPartition.append(target, *(args.empty? ? extras : args), **kwargs)
|
194
193
|
self
|
195
194
|
end
|
196
195
|
|
@@ -207,42 +206,82 @@ module Squared
|
|
207
206
|
self
|
208
207
|
end
|
209
208
|
|
210
|
-
def
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
209
|
+
def arg?(*args, **kwargs)
|
210
|
+
OptionPartition.arg?(target, *args, **kwargs)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
class JoinSet < Set
|
215
|
+
def self.to_s
|
216
|
+
super[/[^:]+\z/, 0]
|
217
|
+
end
|
218
|
+
|
219
|
+
attr_reader :delim
|
215
220
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
221
|
+
def initialize(data = [], delim: ' ')
|
222
|
+
super(data.compact)
|
223
|
+
@delim = delim
|
224
|
+
end
|
225
|
+
|
226
|
+
def last(val, pat)
|
227
|
+
(@last ||= []).append([val, pat, $1]) if val =~ pat
|
228
|
+
self << val
|
229
|
+
end
|
230
|
+
|
231
|
+
def pass(&blk)
|
232
|
+
ret = to_a.map!(&:to_s).reject(&:empty?)
|
233
|
+
@last&.each do |val, pat, key|
|
234
|
+
i = []
|
235
|
+
j = nil
|
236
|
+
ret.each_with_index do |opt, index|
|
237
|
+
if opt == val
|
238
|
+
j = index
|
239
|
+
elsif j && opt[pat, 1] == key
|
240
|
+
i << index
|
222
241
|
end
|
223
|
-
i = 0
|
224
242
|
end
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
243
|
+
next unless j && !i.empty?
|
244
|
+
|
245
|
+
val = ret[j]
|
246
|
+
cur = j
|
247
|
+
i.each do |k|
|
248
|
+
ret[cur] = ret[k]
|
249
|
+
cur = k
|
230
250
|
end
|
231
|
-
|
232
|
-
target.clear
|
251
|
+
ret[i.last] = val
|
233
252
|
end
|
234
|
-
|
235
|
-
self
|
253
|
+
block_given? ? ret.reject(&blk) : ret
|
236
254
|
end
|
237
255
|
|
238
|
-
def
|
239
|
-
|
240
|
-
|
241
|
-
self
|
256
|
+
def and(*args)
|
257
|
+
self << '&&'
|
258
|
+
merge args
|
242
259
|
end
|
243
260
|
|
244
|
-
def
|
245
|
-
|
261
|
+
def or(*args)
|
262
|
+
self << '||'
|
263
|
+
merge args
|
264
|
+
end
|
265
|
+
|
266
|
+
def with(*args, &blk)
|
267
|
+
temp('&&', *args, &blk)
|
268
|
+
end
|
269
|
+
|
270
|
+
def temp(*args, &blk)
|
271
|
+
args.compact!
|
272
|
+
ret = pass(&blk)
|
273
|
+
ret = Set.new(ret.concat(args)).to_a unless args.empty?
|
274
|
+
ret.join(@delim)
|
275
|
+
end
|
276
|
+
|
277
|
+
def done
|
278
|
+
ret = to_s
|
279
|
+
clear
|
280
|
+
ret
|
281
|
+
end
|
282
|
+
|
283
|
+
def to_s
|
284
|
+
pass.join(@delim)
|
246
285
|
end
|
247
286
|
end
|
248
287
|
end
|
@@ -3,16 +3,6 @@
|
|
3
3
|
module Squared
|
4
4
|
module Workspace
|
5
5
|
module Project
|
6
|
-
class << self
|
7
|
-
attr_accessor :line_width
|
8
|
-
|
9
|
-
def max_width(lines)
|
10
|
-
n = [lines.max_by(&:size).size, 80].max
|
11
|
-
[n, Rake.application.terminal_width].min
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
@line_width = ENV.fetch('LOG_COLUMNS', 80).to_i
|
16
6
|
end
|
17
7
|
end
|
18
8
|
end
|