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.
@@ -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 push exec].freeze,
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
- return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || rakefile.empty?
105
+ @rakelist = nil
106
+ return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || (file = rakefile).nil?
106
107
 
107
108
  begin
108
- File.foreach(rakefile) do |line|
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 if rakefile.empty?
138
+ next unless rakefile
138
139
 
139
- format_desc action, nil, "task+,opts*|#{indexchar}index+|#,pattern*"
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, "rake[#{indexchar}N]", 'tasks', grep: args.extras, from: rakefile,
143
- each: ->(val) { val[0] + val[1].to_s })
144
- else
145
- args, opts = args.to_a.partition { |val| indexitem(val) }
146
- if args.empty?
147
- rake(opts: opts)
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 = read_rakefile
150
- while (n, pre = indexitem(args.shift))
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
- irb(gemname, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
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, 'opts*', before: case action
180
- when 'cache', 'check' then nil
181
- else 'command+' end)
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.extras
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, :update
211
- format_desc(action, flag, 'opts*', after: case flag
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(action, flag, 'opts*', after: flag == :pristine ? 'name*|name?@version' : 'name*')
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.extras
223
+ args = args.to_a.drop(1)
233
224
  unless file && !file.include?('*')
234
- file, opts, prog = choice_index('Select a file', Dir.glob(file || (path + '*.rb')),
235
- values: (file ? [] : ['Options']) << 'Arguments',
236
- force: true, series: !args.include?('v'))
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
- prog = opts
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: prog)
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 = Array(glob || '**/*')
298
- Array(from).each_with_index do |val, i|
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(cmd.to_s)
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+(["'])(.+?)\1|remote:\s+(\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\w+=/)
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.unshift(shell_quote(path + file))
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
- name = `rbenv version-name`
476
- name =~ SEM_VER ? "ruby #{name}" : name
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`.sub(/^v/, '')}"
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
- if (val = option('document', prefix: 'gem', ignore: false))
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('document', val)
667
+ basic_option 'document', val
673
668
  end
674
669
  end
675
- if (val = option('user-install', prefix: 'gem', ignore: false))
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
- print_status(major, minor, patch, from: :outdated)
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
- spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *Dir.glob(path + '*.gemspec')]
693
- op << File.basename(spec) if (spec = spec.find { |file| File.exist?(file) })
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('gem not found', hint: file)
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
- case flag
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
- if flag == :pristine
732
- append_repeat 'skip', op.extras
733
- op.reset
734
- else
735
- op.clear
736
- end
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
- pre = name[0, n]
745
- ver = name[(n + 1)..-1]
725
+ op << shell_escape(name[0, n])
726
+ ver = name[n + 1..-1]
746
727
  end
747
- op.adjoin(pre, shell_option('version', ver))
748
- .clear(items)
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', args: nil)
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 = args ? [] : ['bundler/setup']
799
- (r << name).each { |val| op << shell_option('r', val, merge: true) }
800
- Array(path).each { |val| op << quote_option('I', val, merge: true) }
801
- if args
802
- op << '--' << args
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
- ver = $1.split(/\s*,\s*/)
853
- ver.unshift(@version).uniq!
854
- ver.each do |val|
855
- next unless out =~ /\(#{Regexp.escape(val)}(?:,[^)]+|\b)\):([^\n]+)/
856
-
857
- set.call(val, $1)
858
- break
859
- end
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&.include?('--quiet'), **kwargs)
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
- @read_rakefile ||= [].tap do |ret|
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
- ret << [$1, $2]
964
- end
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 @rakefile if @rakefile
963
+ return unless (file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? })
983
964
 
984
- file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }
985
- @rakefile = file ? path + file : ''
965
+ path + file
986
966
  end
987
967
 
988
968
  def rakepwd
989
- return if pwd? || Rake::VERSION < '13.0.4'
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 if pwd? || Gem::VERSION < '3.4.2'
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(target.first)
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
- target.any? { |opt| r.any? { |val| opt&.match?(val) } }
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 : Set.new(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 = extras if args.empty?
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 adjoin(*args, start: false)
211
- i = -1
212
- (items = to_a).each_with_index do |val, index|
213
- if i == 0
214
- next unless val.start_with?('-')
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
- i = index
217
- break
218
- elsif index > 0 && !val.start_with?('-')
219
- if start
220
- i = index + (start.is_a?(Numeric) ? start : 1)
221
- break
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
- end
226
- if i > 0
227
- if args.empty?
228
- args = dup
229
- reset
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
- args = items[0...i] + args + items[i..-1]
232
- target.clear
251
+ ret[i.last] = val
233
252
  end
234
- merge(args)
235
- self
253
+ block_given? ? ret.reject(&blk) : ret
236
254
  end
237
255
 
238
- def reset(errors: false)
239
- extras.clear
240
- clear(errors: true) if errors
241
- self
256
+ def and(*args)
257
+ self << '&&'
258
+ merge args
242
259
  end
243
260
 
244
- def arg?(*args, **kwargs)
245
- OptionPartition.arg?(target, *args, **kwargs)
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