squared 0.7.5 → 0.7.7

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.
@@ -663,11 +663,7 @@ module Squared
663
663
  if group && @banner.group.key?(group = group.to_sym)
664
664
  @banner.group[group]
665
665
  else
666
- ref.reverse_each do |val|
667
- next unless @banner.ref.key?(val)
668
-
669
- return @banner.ref[val]
670
- end
666
+ ref.reverse_each { |val| return @banner.ref[val] if @banner.ref.key?(val) }
671
667
  @banner.ref[:_] if @banner.ref.key?(:_)
672
668
  end
673
669
  end
@@ -950,7 +946,7 @@ module Squared
950
946
  log_console(*args, pipe: kwargs[:pipe] || pipe)
951
947
  end
952
948
 
953
- def script_command(task, val, group, ref, on, &blk)
949
+ def script_command(task, val, group, ref, on = nil, &blk)
954
950
  if block_given?
955
951
  val = Struct::RunData.new(val, blk)
956
952
  elsif !val
@@ -961,7 +957,7 @@ module Squared
961
957
  as_a group, :to_sym
962
958
  else
963
959
  label = :ref
964
- as_a ref, :to_sym
960
+ as_a(ref || :_, :to_sym)
965
961
  end.each do |name|
966
962
  @script[label][name][task] = val
967
963
  @events[label][name][task] = on if on.is_a?(Hash)
@@ -1014,6 +1010,8 @@ module Squared
1014
1010
  nil
1015
1011
  elsif ref && target[:ref].key?(ref)
1016
1012
  target[:ref][ref]
1013
+ else
1014
+ target[:ref][:_]
1017
1015
  end
1018
1016
  end
1019
1017
 
@@ -25,7 +25,7 @@ module Squared
25
25
  VAR_SET = %i[parent global script index envname desc dependfile dependname dependindex theme archive env graph
26
26
  dev prod timeout pass only exclude serve asdf].freeze
27
27
  BLK_SET = %i[run depend doc lint test copy clean].freeze
28
- SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+))?[-.]?(\S+)?\b/.freeze
28
+ SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+))?(?:([-.])?(\S+))?\b/.freeze
29
29
  URI_SCHEME = %r{\A([a-z][a-z\d+-.]*)://[^@:\[\]\\^<>|\s]}i.freeze
30
30
  TASK_METADATA = Rake::TaskManager.record_task_metadata
31
31
  private_constant :OPTIONS, :VAR_SET, :BLK_SET, :SEM_VER, :URI_SCHEME, :TASK_METADATA
@@ -1351,7 +1351,7 @@ module Squared
1351
1351
  else
1352
1352
  if series?(obj)
1353
1353
  obj.each(&:call)
1354
- elsif obj.is_a?(Array) && obj.none?(String)
1354
+ elsif obj.is_a?(Array) && obj.any? { |val| !val.is_a?(String) }
1355
1355
  build(*obj, **kwargs)
1356
1356
  elsif obj
1357
1357
  run_s(*Array(obj), **kwargs)
@@ -1557,8 +1557,8 @@ module Squared
1557
1557
 
1558
1558
  def session(*cmd, prefix: cmd.first, main: true, path: true, options: true)
1559
1559
  prefix = prefix.to_s.stripext
1560
- if path && (val = shell_bin(prefix))
1561
- cmd[0] = shell_quote(val, force: false)
1560
+ if path && (bin = shell_bin(prefix))
1561
+ cmd[0] = shell_quote(bin, force: false)
1562
1562
  end
1563
1563
  ret = JoinSet.new(cmd)
1564
1564
  if options
@@ -1576,7 +1576,9 @@ module Squared
1576
1576
  command = :"#{prefix}_#{$1}"
1577
1577
  cache[1][command] || @timeout[command]
1578
1578
  end || cache[1][prefix.to_sym] || @timeout[prefix.to_sym]
1579
- main ? @session = ret : ret
1579
+ return ret unless main
1580
+
1581
+ @session = ret
1580
1582
  end
1581
1583
 
1582
1584
  def session_timeout(cmd)
@@ -1622,7 +1624,7 @@ module Squared
1622
1624
  args.unshift(*a)
1623
1625
  OptionPartition.uniq!(args, pass) if pass
1624
1626
  end
1625
- kwargs&.update(b) { |_, val| val }
1627
+ kwargs&.update(b) { |_, obj| obj }
1626
1628
  nil
1627
1629
  end
1628
1630
 
@@ -1638,7 +1640,7 @@ module Squared
1638
1640
  return cmd.to_s unless cmd.respond_to?(:done)
1639
1641
 
1640
1642
  raise_error 'no command added', hint: cmd.first unless cmd.size > 1
1641
- @session = nil if cmd == @session
1643
+ @session = nil if cmd.equal?(@session)
1642
1644
  cmd.done
1643
1645
  end
1644
1646
 
@@ -1655,12 +1657,14 @@ module Squared
1655
1657
  args.each do |key|
1656
1658
  next unless (ret = env(env_key(prefix.to_s.stripext, key), **kwargs)) && (!pat || ret.match?(pat))
1657
1659
 
1658
- if path
1659
- target << quote_option(key, basepath(ret))
1660
- elsif quote
1661
- target << quote_option(key, ret)
1662
- elsif escape
1663
- target << shell_option(key, ret)
1660
+ if target
1661
+ if path
1662
+ target << quote_option(key, basepath(ret))
1663
+ elsif quote
1664
+ target << quote_option(key, ret)
1665
+ elsif escape
1666
+ target << shell_option(key, ret)
1667
+ end
1664
1668
  end
1665
1669
  return block_given? ? yield(ret) : ret
1666
1670
  end
@@ -1790,7 +1794,7 @@ module Squared
1790
1794
  workspace.format_desc([@desc, action, flag].compact, opts, **kwargs)
1791
1795
  end
1792
1796
 
1793
- def format_banner(cmd, banner: true, hint: nil, strip: nil, quote: false)
1797
+ def format_banner(cmd, banner: true, hint: nil, strip: nil, quote: false, command: true)
1794
1798
  return unless banner && banner?
1795
1799
 
1796
1800
  if (data = workspace.banner_get(*@ref, group: group))
@@ -1803,15 +1807,17 @@ module Squared
1803
1807
  if verbose
1804
1808
  out = []
1805
1809
  if data.command
1806
- if cmd =~ /\A(?:"((?:[^"]|(?<=\\)")+)"|'((?:[^']|(?<=\\)')+)'|(\S+))( |\z)/
1807
- arg = $3 || $2 || $1
1808
- cmd = cmd.sub(arg, data.command == 0 ? arg.stripext : arg.stripext.upcase)
1809
- end
1810
- if strip || (strip.nil? && data.order.include?(:path))
1811
- cmd = cmd.gsub(/(?:#{s = Regexp.escape(File.join(path, ''))}?(?=["'])|#{s})/, '')
1812
- .gsub(/(?: -[^ ])? (?:""|'')/, '')
1810
+ if command
1811
+ if cmd =~ /\A(?:"((?:[^"]|(?<=\\)")+)"|'((?:[^']|(?<=\\)')+)'|(\S+))( |\z)/
1812
+ arg = $3 || $2 || $1
1813
+ cmd = cmd.sub(arg, data.command == 0 ? arg.stripext : arg.stripext.upcase)
1814
+ end
1815
+ if strip || (strip.nil? && data.order.include?(:path))
1816
+ cmd = cmd.gsub(/(?:#{s = Regexp.escape(File.join(path, ''))}?(?=["'])|#{s})/, '')
1817
+ .gsub(/(?: -[^ ])? (?:""|'')/, '')
1818
+ end
1819
+ cmd = cmd.gsub(/(?<= )(["'])([\w.-]+)\1(?= |\z)/, '\2') unless quote
1813
1820
  end
1814
- cmd.gsub!(/(?<= )(["'])([\w.-]+)\1(?= |\z)/, '\2') unless quote
1815
1821
  out << cmd.subhint(hint)
1816
1822
  end
1817
1823
  data.order.each do |val|
@@ -1827,7 +1833,7 @@ module Squared
1827
1833
  __send__ meth
1828
1834
  end
1829
1835
  end
1830
- val = val.compact.join(s)
1836
+ val = val.reject { |item| !item || item == true }.join(s)
1831
1837
  next unless found && !val.empty?
1832
1838
  elsif (val = __send__(val)).nil?
1833
1839
  next
@@ -2231,9 +2237,9 @@ module Squared
2231
2237
 
2232
2238
  a, b = [a.first, b.first].map do |c|
2233
2239
  d = begin
2234
- Integer(c[5]).to_s
2240
+ Integer(c[6]).to_s
2235
2241
  rescue
2236
- c[5] ? '-1' : '0'
2242
+ c[6] ? '-1' : '0'
2237
2243
  end
2238
2244
  [c[0], c[2], c[4] || '0', d]
2239
2245
  end
@@ -2276,7 +2282,7 @@ module Squared
2276
2282
  end
2277
2283
 
2278
2284
  def semmajor?(cur, want)
2279
- (cur[0] == '0' && want[0] == '0' ? cur[2] != want[2] : cur[0] != want[0]) && !want[5]
2285
+ (cur[0] == '0' && want[0] == '0' ? cur[2] != want[2] : cur[0] != want[0]) && !want[6]
2280
2286
  end
2281
2287
 
2282
2288
  def semgte?(val, other = nil)
@@ -2393,7 +2399,7 @@ module Squared
2393
2399
  return if from == false
2394
2400
 
2395
2401
  require 'timeout'
2396
- unless (path.to_s == Dir.pwd || pass == true) && (workspace.mri? || !workspace.windows?)
2402
+ unless (path.to_s == Dir.pwd || pass) && (workspace.mri? || !workspace.windows?)
2397
2403
  pwd = Dir.pwd
2398
2404
  Dir.chdir(path)
2399
2405
  end
@@ -2671,7 +2677,7 @@ module Squared
2671
2677
  when true, false
2672
2678
  run
2673
2679
  else
2674
- $?.success?
2680
+ $?&.success?
2675
2681
  end
2676
2682
  if cond.none? { |val| val == false }
2677
2683
  if block_given?
@@ -2696,7 +2702,7 @@ module Squared
2696
2702
  end
2697
2703
 
2698
2704
  def stdout?
2699
- !!verbose && !stdin?
2705
+ !quiet? && !stdin?
2700
2706
  end
2701
2707
 
2702
2708
  def verbose?
@@ -419,9 +419,15 @@ module Squared
419
419
  when :bake
420
420
  append_file(0, index: 3) unless from || op.arg?('f', 'file') || !anypath?(*COMPOSEFILE)
421
421
  unless op.empty?
422
- context = op.pop if Dir.exist?(op.last) && projectpath?(op.last)
422
+ if !context && op.size > 1 && exist?(op.last, type: 'd')
423
+ pat = /\btarget\s+"#{Regexp.escape(op.last)}"/
424
+ context = op.pop if op.values_of('f', 'file').none? { |f| basepath!(f)&.read&.match?(pat) }
425
+ end
426
+ if context
427
+ context = basepath context
428
+ op.each { |name| op.add_option('set', "#{name}.context=#{context}", escape: false) }
429
+ end
423
430
  op.append(escape: true, strip: /^:/, clear: true)
424
- contextdir context if context
425
431
  end
426
432
  end
427
433
  op.clear(pass: false)
@@ -472,6 +478,7 @@ module Squared
472
478
  end
473
479
  run(from: from)
474
480
  end
481
+ alias compose_ compose!
475
482
 
476
483
  def container(flag, opts = [], id: nil)
477
484
  cmd, opts = docker_session('container', flag, opts: opts)
@@ -332,7 +332,7 @@ module Squared
332
332
  end
333
333
 
334
334
  subtasks({
335
- 'branch' => %i[create track delete move copy list current].freeze,
335
+ 'branch' => %i[create track delete move copy list all current].freeze,
336
336
  'checkout' => %i[commit branch track detach path].freeze,
337
337
  'commit' => %i[add all amend amend-orig fixup].freeze,
338
338
  'diff' => %i[head branch files view between contain].freeze,
@@ -730,12 +730,7 @@ module Squared
730
730
  task flag do |_, args|
731
731
  branch flag, args.to_a
732
732
  end
733
- when :current
734
- format_desc action, flag
735
- task flag do
736
- branch flag
737
- end
738
- else
733
+ when :move, :copy
739
734
  format_desc action, flag, 'branch,oldbranch?'
740
735
  task flag, [:branch, :oldbranch] do |_, args|
741
736
  if (branch = args.branch)
@@ -746,6 +741,11 @@ module Squared
746
741
  end
747
742
  branch(flag, refs: [oldbranch, branch])
748
743
  end
744
+ else
745
+ format_desc action, flag
746
+ task flag do
747
+ branch flag
748
+ end
749
749
  end
750
750
  when 'switch'
751
751
  case flag
@@ -1090,7 +1090,7 @@ module Squared
1090
1090
  cmd, opts = git_session('rebase', opts: opts)
1091
1091
  case flag
1092
1092
  when :branch
1093
- return unless upstream
1093
+ raise ArgumentError, 'no upstream branch' unless upstream
1094
1094
 
1095
1095
  op = OptionPartition.new(opts, OPT_GIT[:rebase], cmd, project: self, strict: strict?,
1096
1096
  no: OPT_GIT[:no][:rebase])
@@ -1098,7 +1098,7 @@ module Squared
1098
1098
  append_head op.shift&.delete_prefix(':')
1099
1099
  op.clear(pass: false)
1100
1100
  when :onto
1101
- return unless upstream
1101
+ raise ArgumentError, 'no base branch/commit' unless upstream
1102
1102
 
1103
1103
  cmd << '--interactive' if option('interactive', 'i')
1104
1104
  cmd << shell_option('onto', commit) if commit
@@ -1169,7 +1169,7 @@ module Squared
1169
1169
  option('no-tags') { opts[:'no-tags'] = true }
1170
1170
  opts.delete(:'recurse-submodules') || opts.delete(:'no-recurse-submodules') if append_submodules(from: :clone)
1171
1171
  append_hash opts
1172
- cmd << '--quiet' if option('quiet') || !verbose
1172
+ cmd << '--quiet' if quiet? || option('quiet')
1173
1173
  append_value(data[0], path, delim: true)
1174
1174
  source(sync: sync, banner: sync && !quiet?, multiple: !sync || quiet?)
1175
1175
  end
@@ -1480,6 +1480,7 @@ module Squared
1480
1480
  append_pathspec op.extras
1481
1481
  source(exception: false)
1482
1482
  end
1483
+ alias log_ log!
1483
1484
 
1484
1485
  def diff(flag, opts = [], refs: [], branch: nil, range: [], index: [], from: :diff)
1485
1486
  cmd, opts = git_session(from, opts: opts)
@@ -1610,7 +1611,7 @@ module Squared
1610
1611
  elsif flag == :'amend-orig' || option('edit', equals: '0')
1611
1612
  co << '--no-edit'
1612
1613
  end
1613
- pu << '--force-with-lease' if amend
1614
+ pu << (option('f', 'force') ? '--force' : '--force-with-lease') if amend
1614
1615
  pu.merge(repotrack(origin, branch))
1615
1616
  adding = git_spawn 'diff --name-only --no-color'
1616
1617
  source op
@@ -1691,7 +1692,7 @@ module Squared
1691
1692
  end
1692
1693
  when :delete
1693
1694
  remote&.each { |val| source git_output('push --delete', *val.split('/', 2).quote!) }
1694
- force, list = refs.partition { |val| val.start_with?('~', '^') }
1695
+ force, list = refs.partition { |val| val.start_with?(/[~^]/) }
1695
1696
  force.each do |val|
1696
1697
  r = '-r' if val.delete!('~')
1697
1698
  source git_output('branch', val.delete!('^') ? '-D' : '-d', r, shell_quote(val))
@@ -1921,7 +1922,7 @@ module Squared
1921
1922
  end)
1922
1923
  case flag
1923
1924
  when :blame
1924
- raise Errno::ENOENT, 'no file target' unless (n = op.index { |s| basepath(s).file? })
1925
+ raise Errno::ENOENT, 'no file target' unless (n = op.index { |val| basepath(val).file? })
1925
1926
 
1926
1927
  op.append(basepath(op.remove_at(n)), delim: true)
1927
1928
  .clear
@@ -1929,7 +1930,7 @@ module Squared
1929
1930
  if op.arg?(*VAL_GIT[:rebase][:send])
1930
1931
  op.clear
1931
1932
  elsif op.empty?
1932
- raise 'no commit target'
1933
+ raise ArgumentError, 'no commit target'
1933
1934
  else
1934
1935
  append_commit(*op.extras)
1935
1936
  end
@@ -2001,6 +2002,10 @@ module Squared
2001
2002
 
2002
2003
  def source(cmd = @session, exception: true, io: false, sync: true, stdout: false, stderr: false, banner: true,
2003
2004
  multiple: false, hint: nil, from: nil, timeout: nil, send: :system, **kwargs)
2005
+ unless cmd
2006
+ print_error('no git session started', subject: project, hint: from, pass: true)
2007
+ return
2008
+ end
2004
2009
  cmd = cmd.target if cmd.is_a?(OptionPartition)
2005
2010
  if io && banner == false
2006
2011
  from = nil
@@ -2068,7 +2073,7 @@ module Squared
2068
2073
  if size == 0
2069
2074
  puts empty_status("No #{type} were #{action}", 'grep', grep.join(', '))
2070
2075
  elsif stdout?
2071
- styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
2076
+ styles = theme.fetch(:banner, []).reject { |val| val.to_s.end_with?('!') }
2072
2077
  styles << :bold if styles.size <= 1
2073
2078
  puts print_footer("#{size} #{size == 1 ? type.sub(/(?:(?<!l)e)?s\z/, '') : type}",
2074
2079
  sub: opt_style(styles, /^(\d+)(.+)$/))
@@ -2118,7 +2123,7 @@ module Squared
2118
2123
  glob = kwargs.fetch(:include, [])
2119
2124
  pass = kwargs.fetch(:exclude, [])
2120
2125
  status_data(*args).map(&:first).each_with_object({}) do |file, out|
2121
- next if !glob.empty? && glob.none? { |val| File.fnmatch?(val, file, File::FNM_DOTMATCH) }
2126
+ next unless glob.empty? || glob.any? { |val| File.fnmatch?(val, file, File::FNM_DOTMATCH) }
2122
2127
  next if pass.any? { |val| File.fnmatch?(val, file, File::FNM_DOTMATCH) }
2123
2128
 
2124
2129
  out[file] = algorithm.hexdigest(File.read(basepath(file)))
@@ -2159,7 +2164,7 @@ module Squared
2159
2164
  end
2160
2165
  op << '--verbose' if (flag || from == :fetch) && stdout? && !op.arg?('quiet')
2161
2166
  if remote
2162
- op.append(remote, delim: true)
2167
+ op.append(remote)
2163
2168
  if (val = option('refspec', target: target, strict: true))
2164
2169
  op.append(split_escape(val))
2165
2170
  else
@@ -2194,12 +2199,10 @@ module Squared
2194
2199
  if !files.empty?
2195
2200
  target << '--' << files.join(' ')
2196
2201
  true
2202
+ elsif expect.is_a?(String)
2203
+ raise expect
2197
2204
  elsif expect
2198
- raise(if expect.is_a?(String)
2199
- expect
2200
- else
2201
- kwargs[:parent] ? 'pathspec not present' : 'pathspec not within worktree'
2202
- end)
2205
+ raise(kwargs[:parent] ? 'pathspec not present' : 'pathspec not within worktree')
2203
2206
  else
2204
2207
  false
2205
2208
  end
@@ -2242,13 +2245,15 @@ module Squared
2242
2245
  end
2243
2246
 
2244
2247
  def foreachref(path, *args, format: nil, chomp: true)
2245
- path = Array(path).map { |val| "refs/#{val}" }
2246
2248
  format &&= quote_option('format', format)
2247
- ret = git_spawn('for-each-ref', format, *args, *path, stdout: workspace.windows?)
2249
+ ret = git_spawn('for-each-ref', format, *args.concat(Array(path).map { |val| "refs/#{val}" }),
2250
+ stdout: workspace.windows?)
2248
2251
  if ret.is_a?(String)
2249
2252
  ret.lines(chomp: chomp)
2253
+ elsif chomp
2254
+ ret.readlines(chomp: chomp)
2250
2255
  else
2251
- chomp ? ret.readlines(chomp: chomp) : ret
2256
+ ret
2252
2257
  end
2253
2258
  end
2254
2259
 
@@ -2292,11 +2297,10 @@ module Squared
2292
2297
  end
2293
2298
 
2294
2299
  def repotrack(origin, branch, quote: true)
2295
- unless origin && branch && (i = origin.index('/'))
2296
- raise_error(ArgumentError, "missing #{origin ? 'branch' : 'remote'} name", hint: origin)
2297
- end
2298
- branch = "#{branch}:#{origin[i.succ..-1]}" unless origin.end_with?("/#{branch}")
2299
- ret = [origin[0..i.pred], branch]
2300
+ n = origin&.index('/')
2301
+ raise_error "missing #{origin ? 'branch' : 'remote'} name", hint: origin unless n && branch
2302
+ branch = "#{branch}:#{origin[n.succ..-1]}" unless origin.end_with?("/#{branch}")
2303
+ ret = [origin[0..n.pred], branch]
2300
2304
  ret.quote! if quote
2301
2305
  ret
2302
2306
  end
@@ -2316,7 +2320,7 @@ module Squared
2316
2320
  end
2317
2321
 
2318
2322
  def matchhead(val)
2319
- val =~ /^(?:(?:HEAD|@)([~^]\d*)?|H(\d+))$/ ? $2 || $1 || '' : nil
2323
+ $2 || $1 || '' if val =~ /^(?:(?:HEAD|@)([~^]\d*)?|H(\d+))$/
2320
2324
  end
2321
2325
 
2322
2326
  def matchpathspec