squared 0.4.14 → 0.5.1

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.
@@ -112,6 +112,7 @@ module Squared
112
112
  @mounts = mounts
113
113
  @secrets = secrets
114
114
  @registry = tagjoin registry, kwargs[:username]
115
+ @file = nil
115
116
  initialize_ref Docker.ref
116
117
  initialize_logger(**kwargs)
117
118
  initialize_env(**kwargs)
@@ -198,8 +199,8 @@ module Squared
198
199
  when :push
199
200
  format_desc action, flag, 'tag,registry/username?,opts*'
200
201
  task flag, [:tag] do |_, args|
201
- tag = param_guard(action, flag, args: args, key: :tag)
202
- image(flag, args.extras, id: tag)
202
+ id = param_guard(action, flag, args: args, key: :tag)
203
+ image(flag, args.extras, id: id)
203
204
  end
204
205
  else
205
206
  format_desc(action, flag, case flag
@@ -267,10 +268,8 @@ module Squared
267
268
  end
268
269
 
269
270
  [args, flags].each_with_index do |target, index|
270
- if target.is_a?(String)
271
- ret << target
272
- elsif (target = append_any(target, target: []))
273
- ret.merge(target.map { |arg| index == 0 ? fill_option(arg) : quote_option('build-arg', arg) })
271
+ if (data = append_any(target, target: []))
272
+ ret.merge(data.map { |arg| index == 0 ? fill_option(arg) : quote_option('build-arg', arg) })
274
273
  end
275
274
  end
276
275
  case from
@@ -294,8 +293,8 @@ module Squared
294
293
  end
295
294
  append_context
296
295
  when :bake, :compose
297
- if (val = option(from == :bake ? 'target' : 'service', ignore: false))
298
- ret.merge(split_escape(val).map! { |s| shell_escape(s) })
296
+ option(from == :bake ? 'target' : 'service', ignore: false) do |a|
297
+ ret.merge(split_escape(a).map! { |b| shell_escape(b) })
299
298
  end
300
299
  end
301
300
  ret
@@ -364,7 +363,7 @@ module Squared
364
363
  args = []
365
364
  tmpfs = true
366
365
  val.split(delim).each do |opt|
367
- k, v, q = split_option(opt)
366
+ k, v, q = split_option opt
368
367
  next unless both.include?(k)
369
368
 
370
369
  if k == 'type'
@@ -504,7 +503,7 @@ module Squared
504
503
  raise_error(id ? "unknown args: #{op.join(', ')}" : 'no id/tag given', hint: from) unless id && op.empty?
505
504
  raise_error('username/registry not provided', hint: from) unless registry
506
505
  registry.chomp!('/')
507
- uri = shell_quote("#{registry}/#{id}")
506
+ uri = shell_quote "#{registry}/#{id}"
508
507
  op << uri
509
508
  img = docker_output 'image', 'tag', id, uri
510
509
  return unless confirm_command(img.to_s, cmd.to_s, target: id, as: registry, title: from)
@@ -607,18 +606,20 @@ module Squared
607
606
  end
608
607
 
609
608
  def append_tag(val, target: @session)
610
- ver = option('version', target: target, ignore: false)
611
- list = case val
612
- when String
613
- val.split(',')
614
- when Array
615
- val
616
- else
617
- []
618
- end
619
- list.each do |s|
620
- s = "#{s.sub(/:latest$/, '')}:#{ver}" if ver && (!s.include?(':') || s.end_with?(':latest'))
621
- target << basic_option('tag', tagname(s))
609
+ case val
610
+ when String
611
+ val.split(',')
612
+ when Array
613
+ val
614
+ else
615
+ []
616
+ end.yield_self do |list|
617
+ ver = option('version', target: target, ignore: false)
618
+ list.each do |s|
619
+ s = "#{s}:#{ver}" if ver && (!s.include?(':') || s.delete_suffix!(':latest'))
620
+ target << basic_option('tag', tagname(s))
621
+ end
622
+ target
622
623
  end
623
624
  end
624
625
 
@@ -648,7 +649,6 @@ module Squared
648
649
  cc = bb.size + 1
649
650
  a = sub_style(ee, styles: theme[:inline])
650
651
  b = "Execute #{sub_style(flag, styles: theme[:active])} on #{a}#{ee == id ? '' : " (#{id})"}"
651
- c, d = no ? ['y/N', 'N'] : ['Y/n', 'Y']
652
652
  e = time_format(time_since(data['CreatedAt']), pass: ['ms'])
653
653
  f = sub_style(ARG[:BORDER][0], styles: theme[:inline])
654
654
  g = ' ' * (cc + 1)
@@ -671,7 +671,7 @@ module Squared
671
671
  puts g + sub_style(ARG[:BORDER][6] + (ARG[:BORDER][1] * w), styles: theme[:inline])
672
672
  found = true
673
673
  index += 1
674
- next unless confirm("#{h + b}? [#{c}] ", d, timeout: 60)
674
+ next unless confirm("#{h + b}?", no ? 'N' : 'Y', timeout: 60)
675
675
 
676
676
  puts if printfirst?
677
677
  end
@@ -681,7 +681,7 @@ module Squared
681
681
  end
682
682
  rescue StandardError => e
683
683
  log.error e
684
- ret = on(:error, from, e)
684
+ ret = on :error, from, e
685
685
  raise if exception && ret != true
686
686
 
687
687
  warn log_message(Logger::WARN, e, pass: true) if warning?
@@ -700,7 +700,7 @@ module Squared
700
700
  a = t.last.capitalize
701
701
  b = sub_style(target, styles: theme[:subject])
702
702
  c = as && sub_style(as, styles: theme[:inline])
703
- confirm("#{a} #{b}#{c ? " as #{c}" : ''}? [y/N] ", 'N', timeout: 60)
703
+ confirm("#{a} #{b}#{c ? " as #{c}" : ''}?", 'N', timeout: 60)
704
704
  end
705
705
 
706
706
  def choice_command(flag)
@@ -758,7 +758,7 @@ module Squared
758
758
  [parse.call(out)]
759
759
  end)
760
760
  cmd << args
761
- print_success if success?(run(cmd)) && ctx.match?(/\A(?:network|tag|save)/)
761
+ print_success if success?(run(cmd)) && ctx.start_with?(/(?:network|tag|save)/)
762
762
  end
763
763
  end
764
764
 
@@ -788,9 +788,10 @@ module Squared
788
788
 
789
789
  def tagname(val)
790
790
  val = val.split(':').map! { |s| charname(s.sub(/^\W+/, '')) }
791
- ret = val.join(':')
792
- ret = val.first if val.size > 1 && ret.size > 128
793
- ret[0..127]
791
+ val.join(':').yield_self do |s|
792
+ s = val.first if val.size > 1 && s.size > 128
793
+ s[0..127]
794
+ end
794
795
  end
795
796
 
796
797
  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,
@@ -914,7 +917,7 @@ module Squared
914
917
  cmd << '--autostash' if option('autostash')
915
918
  else
916
919
  cmd << '--autostash' if flag == :autostash
917
- if (val = option('rebase', ignore: false))
920
+ option('rebase', ignore: false) do |val|
918
921
  cmd << case val
919
922
  when '0', 'false'
920
923
  '--no-rebase'
@@ -977,23 +980,26 @@ module Squared
977
980
 
978
981
  cmd = git_session('clone', worktree: false)
979
982
  opts = data[1].dup
980
- if (val = option('depth', ignore: false))
983
+ option('depth', ignore: false) do |val|
981
984
  if (n = val.to_i) > 0
982
985
  opts[:depth] = n
983
986
  else
984
987
  opts.delete(:depth)
985
988
  end
986
989
  end
987
- opts[:origin] = val if (val = option('origin', ignore: false))
988
- if (val = option('branch', strict: true))
989
- opts[:branch] = val
990
+ option('origin', ignore: false) { |val| opts[:origin] = val }
991
+ if (branch = option('branch', strict: true))
992
+ opts[:branch] = branch
990
993
  opts.delete(:revision)
991
- elsif (val = option('revision', strict: true))
992
- opts[:revision] = val
993
- opts.delete(:branch)
994
- opts.delete(:mirror)
994
+ else
995
+ option('revision', strict: true) do |val|
996
+ opts[:revision] = val
997
+ opts.delete(:branch)
998
+ opts.delete(:mirror)
999
+ end
995
1000
  end
996
- opts[:local] = val != '0' if (val = option('local', strict: true))
1001
+ option('local', strict: true) { |val| opts[:local] = val != '0' }
1002
+ option('bare') { |val| opts[:bare] = val }
997
1003
  opts.delete(:'recurse-submodules') || opts.delete(:'no-recurse-submodules') if append_submodules(from: :clone)
998
1004
  append_hash opts
999
1005
  cmd << '--quiet' unless verbose
@@ -1036,9 +1042,7 @@ module Squared
1036
1042
  end
1037
1043
  op.clear
1038
1044
  when :clear
1039
- if confirm("Remove #{sub_style('all', styles: theme[:active])} stash entries? [y/N] ", 'N')
1040
- source(stdout: true)
1041
- end
1045
+ source(stdout: true) if confirm("Remove #{sub_style('all', styles: theme[:active])} stash entries?", 'N')
1042
1046
  return
1043
1047
  when :list
1044
1048
  op.clear
@@ -1059,7 +1063,7 @@ module Squared
1059
1063
  cmd = git_session 'status'
1060
1064
  cmd << (option('long') ? '--long' : '--short')
1061
1065
  cmd << '--branch' if option('branch')
1062
- if (val = option('ignore-submodules', ignore: false))
1066
+ option('ignore-submodules', ignore: false) do |val|
1063
1067
  cmd << basic_option('ignore-submodules', case val
1064
1068
  when '0', 'none'
1065
1069
  'none'
@@ -1080,7 +1084,7 @@ module Squared
1080
1084
  { pat: /^(.)([A-Z?!])(.+)$/, styles: r, index: 2 },
1081
1085
  { pat: /^([A-Z?!])(.+)$/, styles: g },
1082
1086
  { pat: /^(\?\?)(.+)$/, styles: r },
1083
- { pat: /^(## )(.+?)(\.{3})(.+)$/, styles: [nil, g, nil, r], index: -1 }
1087
+ { pat: /^(## )((?~\.{3}))(\.{3})(.+)$/, styles: [nil, g, nil, r], index: -1 }
1084
1088
  ]
1085
1089
  else
1086
1090
  [pat: /^(\t+)([a-z]+: +.+)$/, styles: r, index: 2]
@@ -1118,9 +1122,9 @@ module Squared
1118
1122
  args = op.to_a
1119
1123
  else
1120
1124
  args = []
1121
- args << basic_option('untracked-files', flag) if (flag = option('untracked-files', prefix: 'git'))
1122
- args << basic_option('ignore-submodules', flag) if (flag = option('ignore-submodules', prefix: 'git'))
1123
- args << basic_option('ignored', flag) if (flag = option('ignored', prefix: 'git'))
1125
+ option('untracked-files', prefix: 'git') { |val| args << basic_option('untracked-files', val) }
1126
+ option('ignore-submodules', prefix: 'git') { |val| args << basic_option('ignore-submodules', val) }
1127
+ option('ignored', prefix: 'git') { |val| args << basic_option('ignored', val) }
1124
1128
  end
1125
1129
  if (cur = workspace.rev_entry(name)) && cur['revision'] == sha && !env('REVBUILD_FORCE')
1126
1130
  files = status_digest(*args, **kwargs)
@@ -1244,7 +1248,7 @@ module Squared
1244
1248
  list_result(ret, 'tags', from: from, grep: op.extras)
1245
1249
  return
1246
1250
  end
1247
- remote ||= option('remote')
1251
+ remote ||= option 'remote'
1248
1252
  source
1249
1253
  git_spawn('push', flag == :delete ? '-d' : nil, remote, *refs.map { |val| shell_quote(val) }) if remote
1250
1254
  end
@@ -1411,12 +1415,12 @@ module Squared
1411
1415
  stdout = false
1412
1416
  case flag
1413
1417
  when :create
1414
- if (arg = option('track', ignore: false))
1415
- cmd << case arg
1418
+ option('track', ignore: false) do |val|
1419
+ cmd << case val
1416
1420
  when '0', 'false'
1417
1421
  '--no-track'
1418
1422
  when 'direct', 'inherit'
1419
- basic_option('track', arg)
1423
+ basic_option 'track', val
1420
1424
  else
1421
1425
  '--track'
1422
1426
  end
@@ -1438,7 +1442,7 @@ module Squared
1438
1442
  remote&.each do |val|
1439
1443
  source git_output('push', '--delete', *val.split('/', 2).map { |s| shell_quote(s) })
1440
1444
  end
1441
- force, list = refs.partition { |val| val.match?(/^[~^]/) }
1445
+ force, list = refs.partition { |val| val.start_with?(/[~^]/) }
1442
1446
  force.each do |val|
1443
1447
  dr = val[0, 2]
1444
1448
  d = dr.include?('^') ? '-D' : '-d'
@@ -1484,7 +1488,7 @@ module Squared
1484
1488
  data = line.sub(/^\*\s+/, '').split(/\s+/)
1485
1489
  a = sub_style(data[0], styles: theme[:inline])
1486
1490
  b = sub_style(data[1], styles: theme[:extra])
1487
- r = /\A(?:\[(.+?)(?=\]\s)\]\s)?(.+)\z/m.match(data[2..-1].join(' '))
1491
+ r = /\A(?:\[((?~\]\s))\]\s)?(.+)\z/m.match(data[2..-1].join(' '))
1488
1492
  if (r1 = r[1]) && r1 =~ /^(.+):(?: ([a-z]+) (\d+),)? ([a-z]+) (\d+)$/
1489
1493
  write = ->(s1, s2) { "#{s1.capitalize.rjust(7)}: #{sub_style(s2, styles: theme[:warn])}" }
1490
1494
  r1 = $1
@@ -1528,7 +1532,7 @@ module Squared
1528
1532
  when 'y', 'Y', '1', 'true'
1529
1533
  '--track'
1530
1534
  when 'direct', 'inherit'
1531
- basic_option('track', track)
1535
+ basic_option 'track', track
1532
1536
  end
1533
1537
  when :detach, :merge
1534
1538
  cmd << "--#{flag}"
@@ -1564,7 +1568,7 @@ module Squared
1564
1568
  when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
1565
1569
  cmd << basic_option('format', val)
1566
1570
  else
1567
- if format.match?(/^t?format:/) || format.include?('%')
1571
+ if format.start_with?(/t?format:/) || format.include?('%')
1568
1572
  cmd << quote_option('pretty', format)
1569
1573
  else
1570
1574
  opts << format
@@ -1740,7 +1744,7 @@ module Squared
1740
1744
  end
1741
1745
  rescue StandardError => e
1742
1746
  log&.error e
1743
- ret = on(:error, from, e)
1747
+ ret = on :error, from, e
1744
1748
  raise if exception && ret != true
1745
1749
 
1746
1750
  warn log_message(Logger::WARN, e, pass: true) if warning?
@@ -1914,9 +1918,7 @@ module Squared
1914
1918
  option_clear files
1915
1919
  true
1916
1920
  else
1917
- if files.empty? && (val = option('pathspec', target: target))
1918
- files = split_escape val
1919
- end
1921
+ option('pathspec', target: target) { |val| files = split_escape val } if files.empty?
1920
1922
  files = projectmap(files, parent: parent, pass: pass)
1921
1923
  if !files.empty?
1922
1924
  target << '--' << files.join(' ')
@@ -1941,28 +1943,28 @@ module Squared
1941
1943
  end
1942
1944
 
1943
1945
  def append_submodules(target: @session, from: nil)
1944
- return unless (val = option('recurse-submodules', target: target, ignore: false))
1945
-
1946
- if from == :clone
1947
- case val
1948
- when '0', 'false'
1949
- target << '--no-recurse-submodules'
1950
- when '1', 'true'
1951
- target << '--recurse-submodules'
1952
- else
1953
- projectmap(split_escape(val)).each do |path|
1954
- target << basic_option('recurse-submodules', path)
1946
+ option('recurse-submodules', target: target, ignore: false) do |val|
1947
+ if from == :clone
1948
+ case val
1949
+ when '0', 'false'
1950
+ target << '--no-recurse-submodules'
1951
+ when '1', 'true'
1952
+ target << '--recurse-submodules'
1953
+ else
1954
+ projectmap(split_escape(val)).each do |path|
1955
+ target << basic_option('recurse-submodules', path)
1956
+ end
1955
1957
  end
1958
+ else
1959
+ target << case val
1960
+ when 'no', '0', 'false'
1961
+ '--no-recurse-submodules'
1962
+ when 'yes', 'on-demand'
1963
+ "--recurse-submodules=#{val}"
1964
+ else
1965
+ '--recurse-submodules'
1966
+ end
1956
1967
  end
1957
- else
1958
- target << case val
1959
- when 'no', '0', 'false'
1960
- '--no-recurse-submodules'
1961
- when 'yes', 'on-demand'
1962
- "--recurse-submodules=#{val}"
1963
- else
1964
- '--recurse-submodules'
1965
- end
1966
1968
  end
1967
1969
  end
1968
1970
 
@@ -2009,22 +2011,21 @@ module Squared
2009
2011
  def repotrack(origin, branch, quote: true)
2010
2012
  i = origin.index('/')
2011
2013
  branch = "#{branch}:#{origin[(i + 1)..-1]}" unless origin.end_with?("/#{branch}")
2012
- ret = [origin[0..(i - 1)], branch]
2013
- quote ? ret.map! { |val| shell_quote(val) } : ret
2014
+ [origin[0..(i - 1)], branch].tap { |ret| ret.map! { |val| shell_quote(val) } if quote }
2014
2015
  end
2015
2016
 
2016
2017
  def commithash(val)
2017
- val[/\A:(\h{5,40})\z/, 1] || val[/\A#\{(\h{5,40})\}\z/, 1]
2018
+ val[/\A:(\h{5,40})\z/, 1]
2018
2019
  end
2019
2020
 
2020
2021
  def commithead(val)
2021
2022
  return val unless (s = matchhead(val))
2022
2023
 
2023
- s.match?(/^\d/) ? "@~#{s}" : "@#{s}"
2024
+ s.start_with?(/\d/) ? "@~#{s}" : "@#{s}"
2024
2025
  end
2025
2026
 
2026
2027
  def matchhead(val)
2027
- val && val =~ /^(?:(?:HEAD|@)([~^]\d*)?|H(\d+))$/ ? $2 || $1 || '' : nil
2028
+ val =~ /^(?:(?:HEAD|@)([~^]\d*)?|H(\d+))$/ ? $2 || $1 || '' : nil
2028
2029
  end
2029
2030
 
2030
2031
  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.extras
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 = Array(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
@@ -369,7 +381,7 @@ module Squared
369
381
  copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbose)
370
382
  rescue StandardError => e
371
383
  log.error e
372
- ret = on(:error, :copy, e)
384
+ ret = on :error, :copy, e
373
385
  raise if exception && ret != true
374
386
  end
375
387
  end
@@ -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')
@@ -445,7 +457,7 @@ module Squared
445
457
  rescue StandardError => e
446
458
  log.error e
447
459
  unless dryrun
448
- ret = on(:error, :outdated, e)
460
+ ret = on :error, :outdated, e
449
461
  raise if exception && ret != true
450
462
  end
451
463
  warn log_message(Logger::WARN, e) if warning?
@@ -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
@@ -619,13 +631,12 @@ module Squared
619
631
  run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(project, styles: theme[:active])}")
620
632
  else
621
633
  on :first, from
622
- pwd_set(from: :publish, dryrun: dryrun) do
634
+ pwd_set(from: from) do
623
635
  require 'open3'
624
- banner = format_banner(cmd.to_s)
636
+ banner = format_banner cmd.to_s
625
637
  Open3.popen2e(cmd.done) do |_, out|
626
- write_lines(out, banner: banner, sub: npmnotice + [
627
- { pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2 }
628
- ])
638
+ write_lines(out, sub: npmnotice + [pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2],
639
+ banner: banner)
629
640
  end
630
641
  end
631
642
  on :last, from
@@ -736,7 +747,7 @@ module Squared
736
747
  end
737
748
  rescue StandardError => e
738
749
  log.debug e
739
- ret = on(:error, :bump, e)
750
+ ret = on :error, :bump, e
740
751
  raise if exception && ret != true
741
752
  end
742
753
  end
@@ -774,9 +785,9 @@ module Squared
774
785
  if script
775
786
  ret = session dependbin, 'run'
776
787
  raise_error("#{dependbin} run: given #{target}", hint: from) unless append_any(target, build: true)
777
- append_any opts if opts
788
+ append_any opts
778
789
  append_loglevel
779
- append_any(args, delim: true) if args
790
+ append_any(args, delim: true)
780
791
  ret
781
792
  else
782
793
  case target
@@ -920,7 +931,7 @@ module Squared
920
931
  end
921
932
 
922
933
  def append_loglevel(target: @session)
923
- level = env('NODE_LOGLEVEL')
934
+ level = env 'NODE_LOGLEVEL'
924
935
  silent = !verbose || level == 'silent'
925
936
  return unless silent || level
926
937