squared 0.4.13 → 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.
@@ -111,6 +111,7 @@ module Squared
111
111
  @mounts = mounts
112
112
  @secrets = secrets
113
113
  @registry = tagjoin registry, kwargs[:username]
114
+ @file = nil
114
115
  initialize_ref Docker.ref
115
116
  initialize_logger(**kwargs)
116
117
  initialize_env(**kwargs)
@@ -197,8 +198,8 @@ module Squared
197
198
  when :push
198
199
  format_desc action, flag, 'tag,registry/username?,opts*'
199
200
  task flag, [:tag] do |_, args|
200
- tag = param_guard(action, flag, args: args, key: :tag)
201
- image(flag, args.extras, id: tag)
201
+ id = param_guard(action, flag, args: args, key: :tag)
202
+ image(flag, args.extras, id: id)
202
203
  end
203
204
  else
204
205
  format_desc(action, flag, case flag
@@ -266,10 +267,8 @@ module Squared
266
267
  end
267
268
 
268
269
  [args, flags].each_with_index do |target, index|
269
- if target.is_a?(String)
270
- ret << target
271
- elsif (target = append_any(target, target: []))
272
- ret.merge(target.map { |arg| index == 0 ? fill_option(arg) : quote_option('build-arg', arg) })
270
+ if (data = append_any(target, target: []))
271
+ ret.merge(data.map { |arg| index == 0 ? fill_option(arg) : quote_option('build-arg', arg) })
273
272
  end
274
273
  end
275
274
  case from
@@ -293,8 +292,8 @@ module Squared
293
292
  end
294
293
  append_context
295
294
  when :bake, :compose
296
- if (val = option(from == :bake ? 'target' : 'service', ignore: false))
297
- ret.merge(split_escape(val).map! { |s| shell_escape(s) })
295
+ option(from == :bake ? 'target' : 'service', ignore: false) do |a|
296
+ ret.merge(split_escape(a).map! { |b| shell_escape(b) })
298
297
  end
299
298
  end
300
299
  ret
@@ -363,7 +362,7 @@ module Squared
363
362
  args = []
364
363
  tmpfs = true
365
364
  val.split(delim).each do |opt|
366
- k, v, q = split_option(opt)
365
+ k, v, q = split_option opt
367
366
  next unless both.include?(k)
368
367
 
369
368
  if k == 'type'
@@ -503,7 +502,7 @@ module Squared
503
502
  raise_error(id ? "unknown args: #{op.join(', ')}" : 'no id/tag given', hint: from) unless id && op.empty?
504
503
  raise_error('username/registry not provided', hint: from) unless registry
505
504
  registry.chomp!('/')
506
- uri = shell_quote("#{registry}/#{id}")
505
+ uri = shell_quote "#{registry}/#{id}"
507
506
  op << uri
508
507
  img = docker_output 'image', 'tag', id, uri
509
508
  return unless confirm_command(img.to_s, cmd.to_s, target: id, as: registry, title: from)
@@ -604,18 +603,20 @@ module Squared
604
603
  end
605
604
 
606
605
  def append_tag(val, target: @session)
607
- ver = option('version', target: target, ignore: false)
608
- list = case val
609
- when String
610
- val.split(',')
611
- when Array
612
- val
613
- else
614
- []
615
- end
616
- list.each do |s|
617
- s = "#{s.sub(/:latest$/, '')}:#{ver}" if ver && (!s.include?(':') || s.end_with?(':latest'))
618
- target << basic_option('tag', tagname(s))
606
+ case val
607
+ when String
608
+ val.split(',')
609
+ when Array
610
+ val
611
+ else
612
+ []
613
+ end.yield_self do |list|
614
+ ver = option('version', target: target, ignore: false)
615
+ list.each do |s|
616
+ s = "#{s}:#{ver}" if ver && (!s.include?(':') || s.delete_suffix!(':latest'))
617
+ target << basic_option('tag', tagname(s))
618
+ end
619
+ target
619
620
  end
620
621
  end
621
622
 
@@ -755,7 +756,7 @@ module Squared
755
756
  [parse.call(out)]
756
757
  end)
757
758
  cmd << args
758
- print_success if success?(run(cmd)) && ctx.match?(/\A(?:network|tag|save)/)
759
+ print_success if success?(run(cmd)) && ctx.start_with?(/(?:network|tag|save)/)
759
760
  end
760
761
  end
761
762
 
@@ -785,9 +786,10 @@ module Squared
785
786
 
786
787
  def tagname(val)
787
788
  val = val.split(':').map! { |s| charname(s.sub(/^\W+/, '')) }
788
- ret = val.join(':')
789
- ret = val.first if val.size > 1 && ret.size > 128
790
- ret[0..127]
789
+ val.join(':').yield_self do |s|
790
+ s = val.first if val.size > 1 && s.size > 128
791
+ s[0..127]
792
+ end
791
793
  end
792
794
 
793
795
  def dnsname(val)
@@ -91,13 +91,13 @@ module Squared
91
91
 
92
92
  data = @revdoc
93
93
  last = keys.pop
94
- for key in keys
94
+ keys.each do |key|
95
95
  if data[key].is_a?(Hash)
96
96
  data = data[key]
97
97
  elsif create
98
98
  data = data[key] = {}
99
99
  else
100
- return
100
+ return nil
101
101
  end
102
102
  end
103
103
  data[last] = val
@@ -157,13 +157,14 @@ module Squared
157
157
  class Git < Base
158
158
  OPT_GIT = {
159
159
  common: %w[c=q bare glob-pathspecs icase-pathspecs literal-pathspecs no-optional-locks no-pager
160
- no-replace-objects noglob-pathspecs paginate config-env=q exec-path=p namespace=p].freeze,
160
+ no-replace-objects noglob-pathspecs paginate attr-source=b config-env=q exec-path=p
161
+ namespace=p].freeze,
161
162
  add: %w[A|all e|edit f|force ignore-errors ignore-missing ignore-removal i|interactive no-all
162
163
  no-ignore-removal n|dry-run p|patch pathspec-file-nul renormalize sparse u|update v|verbose
163
164
  chmod=b pathspec-from-file=p].freeze,
164
- branch: %w[a|all create-reflog i|ignore-case q|quiet r|remotes v|verbose vv abbrev=i color=b column=b
165
- contains=b format=q merged=b no-contains=b no-merged=b points-at=b u|set-upstream-to=b sort=q
166
- t|track=b].freeze,
165
+ branch: %w[a|all create-reflog i|ignore-case omit-empty q|quiet r|remotes v|verbose vv abbrev=i color=b
166
+ column=b contains=b format=q merged=b no-contains=b no-merged=b points-at=b u|set-upstream-to=b
167
+ sort=q t|track=b].freeze,
167
168
  checkout: %w[l d|detach f|force ignore-other-worktrees ignore-skip-worktree-bits m|merge p|patch
168
169
  pathspec-file-nul q|quiet ours theirs conflict=b orphan=b pathspec-from-file=p t|track=b].freeze,
169
170
  diff: {
@@ -171,7 +172,8 @@ module Squared
171
172
  show: %w[s exit-code histogram].freeze
172
173
  }.freeze,
173
174
  fetch: {
174
- base: %w[multiple progress P|prune-tags refetch stdin u|update-head-ok recurse-submodules-default=b].freeze,
175
+ base: %w[multiple porcelain progress P|prune-tags refetch stdin u|update-head-ok
176
+ recurse-submodules-default=b].freeze,
175
177
  pull: %w[4 6 n t a|append atomic dry-run f|force k|keep negotiate-only prefetch p|prune q|quiet
176
178
  set-upstream unshallow update-shallow v|verbose deepen=i depth=i j|jobs=i negotiation-tip=q
177
179
  recurse-submodules=v refmap=q o|server-option=q shallow-exclude=b shallow-since=v
@@ -196,9 +198,9 @@ module Squared
196
198
  branches=q? committer=q decorate=b decorate-refs=q decorate-refs-exclude=q exclude=q
197
199
  exclude-hidden=b glob=q grep=q grep-reflog=q n|max-count=i max-parents=i min-parents=i no-walk=b?
198
200
  remotes=q? since=q since-as-filter=q skip=i tags=q? until=q].freeze,
199
- format: %w[t children combined-all-paths oneline left-right no-diff-merges parents relative-date
200
- show-signature date=q diff-merges=b encoding=b expand-tabs=i format=q notes=b pretty=q?
201
- show-linear-break=q?].freeze,
201
+ format: %w[t children combined-all-paths dd oneline left-right no-diff-merges parents relative-date
202
+ show-notes-by-default show-signature date=q diff-merges=b encoding=b expand-tabs=i format=q
203
+ notes=b pretty=q? show-linear-break=q?].freeze,
202
204
  diff: %w[p R u z B=bm? C=bm? l=im G=qm I=qm M=bm? O=qm S=qm U=im binary check compact-summary cumulative
203
205
  find-copies-harder full-index W|function-context w|ignore-all-space ignore-blank-lines
204
206
  ignore-cr-at-eol ignore-space-at-eol b|ignore-space-change D|irreversible-delete graph
@@ -228,12 +230,13 @@ module Squared
228
230
  theirs W|worktree conflict=b pathspec-from-file=p s|source=b].freeze,
229
231
  rev_parse: %w[absolute-git-dir all git-common-dir git-dir is-bare-repository is-inside-git-dir
230
232
  is-inside-work-tree is-shallow-repository local-env-vars no-revs not q|quiet revs-only
231
- shared-index-path show-cdup show-prefix show-superproject-working-tree show-toplevel sq sq-quote
232
- symbolic symbolic-full-name verify abbrev-ref=b? after=q before=q branches=q? default=q
233
- disambiguate=b exclude=q exclude-hidden=b git-path=p glob=q path-format=b? prefix=q remotes=q?
234
- resolve-git-dir=p short=i? show-object-format=b? since=q tags=q? until=q].freeze,
235
- show: %w[t combined-all-paths no-diff-merges remerge-diff show-signature diff-merges=b encoding=b
236
- expand-tabs=i notes=q show-notes=q?].freeze,
233
+ shared-index-path show-cdup show-prefix show-ref-format show-superproject-working-tree
234
+ show-toplevel sq sq-quote symbolic symbolic-full-name verify abbrev-ref=b? after=q before=q
235
+ branches=q? default=q disambiguate=b exclude=q exclude-hidden=b git-path=p glob=q
236
+ output-object-format=b path-format=b? prefix=q remotes=q? resolve-git-dir=p short=i?
237
+ show-object-format=b? since=q tags=q? until=q].freeze,
238
+ show: %w[t combined-all-paths no-diff-merges remerge-diff show-notes-by-default show-signature diff-merges=b
239
+ encoding=b expand-tabs=i notes=q show-notes=q?].freeze,
237
240
  stash: {
238
241
  common: %w[q|quiet].freeze,
239
242
  push: %w[a|all u|include-untracked k|keep-index no-keep-index no-include-untracked pathspec-file-nul
@@ -242,8 +245,8 @@ module Squared
242
245
  apply: %w[index].freeze
243
246
  }.freeze,
244
247
  status: %w[u|ignore-submodules=bm? ignored=b? untracked-files=b?],
245
- tag: %w[n=im cleanup=b create-reflog i|ignore-case color=b? column=b contains=b? format=q merged=b?
246
- no-contains=b? no-merged=b? points-at=q sort=q].freeze,
248
+ tag: %w[n=im cleanup=b create-reflog i|ignore-case omit-empty color=b? column=b contains=b? format=q merged=b?
249
+ no-contains=b? no-merged=b? points-at=q sort=q trailer=q].freeze,
247
250
  no: {
248
251
  branch: %w[color color-moved column track].freeze,
249
252
  checkout: %w[overwrite-ignore guess overlay progress recurse-submodules track].freeze,
@@ -913,7 +916,7 @@ module Squared
913
916
  cmd << '--autostash' if option('autostash')
914
917
  else
915
918
  cmd << '--autostash' if flag == :autostash
916
- if (val = option('rebase', ignore: false))
919
+ option('rebase', ignore: false) do |val|
917
920
  cmd << case val
918
921
  when '0', 'false'
919
922
  '--no-rebase'
@@ -976,23 +979,26 @@ module Squared
976
979
 
977
980
  cmd = git_session('clone', worktree: false)
978
981
  opts = data[1].dup
979
- if (val = option('depth', ignore: false))
982
+ option('depth', ignore: false) do |val|
980
983
  if (n = val.to_i) > 0
981
984
  opts[:depth] = n
982
985
  else
983
986
  opts.delete(:depth)
984
987
  end
985
988
  end
986
- opts[:origin] = val if (val = option('origin', ignore: false))
987
- if (val = option('branch', strict: true))
988
- opts[:branch] = val
989
+ option('origin', ignore: false) { |val| opts[:origin] = val }
990
+ if (branch = option('branch', strict: true))
991
+ opts[:branch] = branch
989
992
  opts.delete(:revision)
990
- elsif (val = option('revision', strict: true))
991
- opts[:revision] = val
992
- opts.delete(:branch)
993
- opts.delete(:mirror)
993
+ else
994
+ option('revision', strict: true) do |val|
995
+ opts[:revision] = val
996
+ opts.delete(:branch)
997
+ opts.delete(:mirror)
998
+ end
994
999
  end
995
- opts[:local] = val != '0' if (val = option('local', strict: true))
1000
+ option('local', strict: true) { |val| opts[:local] = val != '0' }
1001
+ option('bare') { |val| opts[:bare] = val }
996
1002
  opts.delete(:'recurse-submodules') || opts.delete(:'no-recurse-submodules') if append_submodules(from: :clone)
997
1003
  append_hash opts
998
1004
  cmd << '--quiet' unless verbose
@@ -1044,7 +1050,7 @@ module Squared
1044
1050
  cmd = git_session 'status'
1045
1051
  cmd << (option('long') ? '--long' : '--short')
1046
1052
  cmd << '--branch' if option('branch')
1047
- if (val = option('ignore-submodules', ignore: false))
1053
+ option('ignore-submodules', ignore: false) do |val|
1048
1054
  cmd << basic_option('ignore-submodules', case val
1049
1055
  when '0', 'none'
1050
1056
  'none'
@@ -1065,7 +1071,7 @@ module Squared
1065
1071
  { pat: /^(.)([A-Z?!])(.+)$/, styles: r, index: 2 },
1066
1072
  { pat: /^([A-Z?!])(.+)$/, styles: g },
1067
1073
  { pat: /^(\?\?)(.+)$/, styles: r },
1068
- { pat: /^(## )(.+?)(\.{3})(.+)$/, styles: [nil, g, nil, r], index: -1 }
1074
+ { pat: /^(## )((?~\.{3}))(\.{3})(.+)$/, styles: [nil, g, nil, r], index: -1 }
1069
1075
  ]
1070
1076
  else
1071
1077
  [pat: /^(\t+)([a-z]+: +.+)$/, styles: r, index: 2]
@@ -1103,9 +1109,9 @@ module Squared
1103
1109
  args = op.to_a
1104
1110
  else
1105
1111
  args = []
1106
- args << basic_option('untracked-files', flag) if (flag = option('untracked-files', prefix: 'git'))
1107
- args << basic_option('ignore-submodules', flag) if (flag = option('ignore-submodules', prefix: 'git'))
1108
- args << basic_option('ignored', flag) if (flag = option('ignored', prefix: 'git'))
1112
+ option('untracked-files', prefix: 'git') { |val| args << basic_option('untracked-files', val) }
1113
+ option('ignore-submodules', prefix: 'git') { |val| args << basic_option('ignore-submodules', val) }
1114
+ option('ignored', prefix: 'git') { |val| args << basic_option('ignored', val) }
1109
1115
  end
1110
1116
  if (cur = workspace.rev_entry(name)) && cur['revision'] == sha && !env('REVBUILD_FORCE')
1111
1117
  files = status_digest(*args, **kwargs)
@@ -1228,7 +1234,7 @@ module Squared
1228
1234
  list_result(ret, 'tags', from: from, grep: op.extras)
1229
1235
  return
1230
1236
  end
1231
- remote ||= option('remote')
1237
+ remote ||= option 'remote'
1232
1238
  source
1233
1239
  git_spawn('push', flag == :delete ? '-d' : nil, remote, *refs.map { |val| shell_quote(val) }) if remote
1234
1240
  end
@@ -1395,12 +1401,12 @@ module Squared
1395
1401
  stdout = false
1396
1402
  case flag
1397
1403
  when :create
1398
- if (arg = option('track', ignore: false))
1399
- cmd << case arg
1404
+ option('track', ignore: false) do |val|
1405
+ cmd << case val
1400
1406
  when '0', 'false'
1401
1407
  '--no-track'
1402
1408
  when 'direct', 'inherit'
1403
- basic_option('track', arg)
1409
+ basic_option 'track', val
1404
1410
  else
1405
1411
  '--track'
1406
1412
  end
@@ -1422,7 +1428,7 @@ module Squared
1422
1428
  remote&.each do |val|
1423
1429
  source git_output('push', '--delete', *val.split('/', 2).map { |s| shell_quote(s) })
1424
1430
  end
1425
- force, list = refs.partition { |val| val.match?(/^[~^]/) }
1431
+ force, list = refs.partition { |val| val.start_with?(/[~^]/) }
1426
1432
  force.each do |val|
1427
1433
  dr = val[0, 2]
1428
1434
  d = dr.include?('^') ? '-D' : '-d'
@@ -1468,7 +1474,7 @@ module Squared
1468
1474
  data = line.sub(/^\*\s+/, '').split(/\s+/)
1469
1475
  a = sub_style(data[0], styles: theme[:inline])
1470
1476
  b = sub_style(data[1], styles: theme[:extra])
1471
- r = /\A(?:\[(.+?)(?=\]\s)\]\s)?(.+)\z/m.match(data[2..-1].join(' '))
1477
+ r = /\A(?:\[((?~\]\s))\]\s)?(.+)\z/m.match(data[2..-1].join(' '))
1472
1478
  if (r1 = r[1]) && r1 =~ /^(.+):(?: ([a-z]+) (\d+),)? ([a-z]+) (\d+)$/
1473
1479
  write = ->(s1, s2) { "#{s1.capitalize.rjust(7)}: #{sub_style(s2, styles: theme[:warn])}" }
1474
1480
  r1 = $1
@@ -1512,7 +1518,7 @@ module Squared
1512
1518
  when 'y', 'Y', '1', 'true'
1513
1519
  '--track'
1514
1520
  when 'direct', 'inherit'
1515
- basic_option('track', track)
1521
+ basic_option 'track', track
1516
1522
  end
1517
1523
  when :detach, :merge
1518
1524
  cmd << "--#{flag}"
@@ -1548,7 +1554,7 @@ module Squared
1548
1554
  when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
1549
1555
  cmd << basic_option('format', val)
1550
1556
  else
1551
- if format.match?(/^t?format:/) || format.include?('%')
1557
+ if format.start_with?(/t?format:/) || format.include?('%')
1552
1558
  cmd << quote_option('pretty', format)
1553
1559
  else
1554
1560
  opts << format
@@ -1636,7 +1642,7 @@ module Squared
1636
1642
  op.swap(list + files)
1637
1643
  end
1638
1644
  end
1639
- append_pathspec(op.extras)
1645
+ append_pathspec op.extras
1640
1646
  verbose = flag == :add && !op.arg?('verbose')
1641
1647
  print_success if success?(source) && verbose
1642
1648
  return
@@ -1890,9 +1896,7 @@ module Squared
1890
1896
  if session_arg?('pathspec-from-file', target: target)
1891
1897
  option_clear files
1892
1898
  else
1893
- if files.empty? && (val = option('pathspec', target: target))
1894
- files = split_escape val
1895
- end
1899
+ option('pathspec', target: target) { |val| files = split_escape val } if files.empty?
1896
1900
  files = projectmap(files, parent: parent, pass: pass)
1897
1901
  if !files.empty?
1898
1902
  target << '--' << files.join(' ')
@@ -1914,28 +1918,28 @@ module Squared
1914
1918
  end
1915
1919
 
1916
1920
  def append_submodules(target: @session, from: nil)
1917
- return unless (val = option('recurse-submodules', target: target, ignore: false))
1918
-
1919
- if from == :clone
1920
- case val
1921
- when '0', 'false'
1922
- target << '--no-recurse-submodules'
1923
- when '1', 'true'
1924
- target << '--recurse-submodules'
1925
- else
1926
- projectmap(split_escape(val)).each do |path|
1927
- target << basic_option('recurse-submodules', path)
1921
+ option('recurse-submodules', target: target, ignore: false) do |val|
1922
+ if from == :clone
1923
+ case val
1924
+ when '0', 'false'
1925
+ target << '--no-recurse-submodules'
1926
+ when '1', 'true'
1927
+ target << '--recurse-submodules'
1928
+ else
1929
+ projectmap(split_escape(val)).each do |path|
1930
+ target << basic_option('recurse-submodules', path)
1931
+ end
1928
1932
  end
1933
+ else
1934
+ target << case val
1935
+ when 'no', '0', 'false'
1936
+ '--no-recurse-submodules'
1937
+ when 'yes', 'on-demand'
1938
+ "--recurse-submodules=#{val}"
1939
+ else
1940
+ '--recurse-submodules'
1941
+ end
1929
1942
  end
1930
- else
1931
- target << case val
1932
- when 'no', '0', 'false'
1933
- '--no-recurse-submodules'
1934
- when 'yes', 'on-demand'
1935
- "--recurse-submodules=#{val}"
1936
- else
1937
- '--recurse-submodules'
1938
- end
1939
1943
  end
1940
1944
  end
1941
1945
 
@@ -1980,22 +1984,21 @@ module Squared
1980
1984
  def repotrack(origin, branch, quote: true)
1981
1985
  i = origin.index('/')
1982
1986
  branch = "#{branch}:#{origin[i + 1..-1]}" unless origin.end_with?("/#{branch}")
1983
- ret = [origin[0..i - 1], branch]
1984
- quote ? ret.map! { |val| shell_quote(val) } : ret
1987
+ [origin[0..i - 1], branch].tap { |ret| ret.map! { |val| shell_quote(val) } if quote }
1985
1988
  end
1986
1989
 
1987
1990
  def commithash(val)
1988
- val[/\A:(\h{5,40})\z/, 1] || val[/\A#\{(\h{5,40})\}\z/, 1]
1991
+ val[/\A:(\h{5,40})\z/, 1]
1989
1992
  end
1990
1993
 
1991
1994
  def commithead(val)
1992
1995
  return val unless (s = matchhead(val))
1993
1996
 
1994
- s.match?(/^\d/) ? "@~#{s}" : "@#{s}"
1997
+ s.start_with?(/\d/) ? "@~#{s}" : "@#{s}"
1995
1998
  end
1996
1999
 
1997
2000
  def matchhead(val)
1998
- val && val =~ /^(?:(?:HEAD|@)([~^]\d*)?|H(\d+))$/ ? $2 || $1 || '' : nil
2001
+ val =~ /^(?:(?:HEAD|@)([~^]\d*)?|H(\d+))$/ ? $2 || $1 || '' : nil
1999
2002
  end
2000
2003
 
2001
2004
  def matchpathspec
@@ -94,6 +94,7 @@ module Squared
94
94
  'add' => nil,
95
95
  'run' => nil,
96
96
  'exec' => nil,
97
+ 'nvm' => nil,
97
98
  'pack' => nil
98
99
  })
99
100
 
@@ -210,6 +211,17 @@ module Squared
210
211
  end
211
212
  run(from: :exec)
212
213
  end
214
+ when 'nvm'
215
+ next unless ENV['NVM_DIR']
216
+
217
+ format_desc action, nil, 'version,args*'
218
+ task action, [:version] do |_, args|
219
+ version = param_guard(action, 'version', args: args, key: :version)
220
+ args = args.to_a.drop(1)
221
+ args << readline('Enter command', force: true) if args.empty?
222
+ args.prepend(File.join(ENV['NVM_DIR'], 'nvm-exec'))
223
+ run(args.join(' '), { 'NODE_VERSION' => version }, banner: false, from: :nvm)
224
+ end
213
225
  when 'pack'
214
226
  format_desc action, nil, 'opts*'
215
227
  task action do |_, args|
@@ -247,7 +259,7 @@ module Squared
247
259
  format_desc(action, flag, 'otp?,dry-run?,public|restricted?', before: flag == :tag ? 'tag' : nil)
248
260
  task flag do |_, args|
249
261
  args = args.to_a
250
- dryrun = true if args.delete('dry-run') || args.delete('true') || args.delete('d')
262
+ dryrun = true if args.delete('dry-run') || args.delete('d')
251
263
  if args.delete('public') || args.delete('p')
252
264
  access = 'public'
253
265
  elsif args.delete('restricted') || args.delete('r')
@@ -339,12 +351,12 @@ module Squared
339
351
  glob = as_a(glob || '**/*')
340
352
  target = []
341
353
  if workspace
342
- Dir.glob(from + '*').each do |path|
343
- next unless (path = Pathname.new(path)).directory?
354
+ from.glob('*').each do |entry|
355
+ next unless entry.directory?
344
356
 
345
- sub = if (proj = @workspace.find(path))
357
+ sub = if (proj = @workspace.find(entry))
346
358
  proj.packagename
347
- elsif (file = path + 'package.json').exist?
359
+ elsif (file = entry + 'package.json').exist?
348
360
  begin
349
361
  doc = JSON.parse(file.read)
350
362
  rescue StandardError => e
@@ -355,9 +367,9 @@ module Squared
355
367
  end
356
368
  end
357
369
  if sub
358
- target << [path, dest.join(into, sub)]
370
+ target << [entry, dest.join(into, sub)]
359
371
  else
360
- log.debug message("package.json in \"#{path}\"", hint: 'not found')
372
+ log.debug message("package.json in \"#{entry}\"", hint: 'not found')
361
373
  end
362
374
  end
363
375
  else
@@ -402,7 +414,7 @@ module Squared
402
414
  else
403
415
  cmd << 'install'
404
416
  end
405
- if (val = option('public-hoist-pattern', ignore: false))
417
+ option('public-hoist-pattern', ignore: false) do |val|
406
418
  split_escape(val).each { |opt| cmd << shell_option('public-hoist-pattern', opt) }
407
419
  end
408
420
  cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0')
@@ -532,7 +544,7 @@ module Squared
532
544
  found.each_with_index do |item, i|
533
545
  a, b, c, d, e = item
534
546
  f = inter && (rev != :major || e || semmajor?(item[5], item[6]))
535
- if f && !confirm_outdated(a, c, (d / 2.0).ceil, lock: e)
547
+ if f && !confirm_outdated(a, c, (d / 2.0).ceil, b, lock: e, col1: col1)
536
548
  cur = -1
537
549
  else
538
550
  cur = modified
@@ -621,13 +633,12 @@ module Squared
621
633
  end
622
634
  unless sync
623
635
  on :first, :publish unless dryrun
624
- pwd_set(from: :publish, dryrun: dryrun) do
636
+ pwd_set(from: :publish) do
625
637
  require 'open3'
626
- banner = format_banner(cmd.to_s)
638
+ banner = format_banner cmd.to_s
627
639
  Open3.popen2e(cmd.done) do |_, out|
628
- write_lines(out, banner: banner, sub: npmnotice + [
629
- { pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2 }
630
- ])
640
+ write_lines(out, sub: npmnotice + [pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2],
641
+ banner: banner)
631
642
  end
632
643
  end
633
644
  on :last, :publish unless dryrun
@@ -780,9 +791,9 @@ module Squared
780
791
  if script
781
792
  ret = session dependbin, 'run'
782
793
  raise_error("#{dependbin} run: given #{target}", hint: from) unless append_any(target, build: true)
783
- append_any opts if opts
794
+ append_any opts
784
795
  append_loglevel
785
- append_any(args, delim: true) if args
796
+ append_any(args, delim: true)
786
797
  ret
787
798
  else
788
799
  case target
@@ -924,7 +935,7 @@ module Squared
924
935
  end
925
936
 
926
937
  def append_loglevel(target: @session)
927
- level = env('NODE_LOGLEVEL')
938
+ level = env 'NODE_LOGLEVEL'
928
939
  silent = !verbose || level == 'silent'
929
940
  return unless silent || level
930
941
 
@@ -442,7 +442,13 @@ module Squared
442
442
  ret
443
443
  end
444
444
 
445
- def variable_set(key, *val, **)
445
+ def variable_set(key, *val, **, &blk)
446
+ if block_given?
447
+ case key
448
+ when :dependfile, :venv, :editable
449
+ val = block_args val, &blk
450
+ end
451
+ end
446
452
  case key
447
453
  when :dependfile
448
454
  req = basepath(*val)
@@ -485,9 +491,7 @@ module Squared
485
491
 
486
492
  def poetry_session(*cmd)
487
493
  ret = session('poetry', *cmd, *preopts)
488
- if (val = option('project', ignore: false))
489
- ret << quote_option('project', path + val)
490
- end
494
+ option('project', ignore: false) { |val| ret << quote_option('project', path + val) }
491
495
  ret
492
496
  end
493
497
 
@@ -560,7 +564,7 @@ module Squared
560
564
  end
561
565
 
562
566
  def append_global(target: @session)
563
- if (val = option('cache-dir', target: target))
567
+ option('cache-dir', target: target) do |val|
564
568
  target << case val
565
569
  when '0', 'false'
566
570
  '--no-cache-dir'
@@ -568,8 +572,8 @@ module Squared
568
572
  quote_option('cache-dir', path + val)
569
573
  end
570
574
  end
571
- target << shell_option('proxy', val) if (val = option('proxy', target: target))
572
- target << quote_option('python', path + val) if (val = option('python', target: target))
575
+ option('proxy', target: target) { |val| target << shell_option('proxy', val) }
576
+ option('python', target: target) { |val| target << quote_option('python', path + val) }
573
577
  append_nocolor(target: target)
574
578
  end
575
579