squared 0.4.17 → 0.4.19

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.
@@ -74,7 +74,7 @@ module Squared
74
74
  @revdoc = JSON.parse(@revfile.read) if @revfile.exist?
75
75
  rescue StandardError => e
76
76
  @revfile = nil
77
- warn log_message(Logger::WARN, e, pass: true) if @warning
77
+ warn log_message(Logger::WARN, e, pass: true)
78
78
  self
79
79
  else
80
80
  @revdoc = {} unless @revdoc.is_a?(Hash)
@@ -301,9 +301,9 @@ module Squared
301
301
  include Rake::DSL
302
302
 
303
303
  def populate(ws, **)
304
- return if ws.series.exclude?(:pull, true)
304
+ return if ws.series.exclude?(:pull, true) || ws.size == 1
305
305
 
306
- namespace(ws.task_name('git')) do |ns|
306
+ namespace ws.task_name('git') do |ns|
307
307
  ws.format_desc(all = ws.task_join(ns.scope.path, 'all'), 'stash|rebase|autostash?,depend?')
308
308
  task 'all' do |_, args|
309
309
  args = args.to_a
@@ -500,10 +500,11 @@ module Squared
500
500
  end
501
501
  when 'stash'
502
502
  format_desc(action, flag, 'opts*', after: case flag
503
- when :push then 'pathspec*'
503
+ when :push then 'pathspec*,:'
504
504
  when :branch then 'name,stash?|:'
505
505
  when :clear, :list then nil
506
- else 'stash?|:' end)
506
+ else 'stash?|:'
507
+ end)
507
508
  task flag do |_, args|
508
509
  stash flag, args.to_a
509
510
  end
@@ -623,12 +624,12 @@ module Squared
623
624
  format_desc action, flag, 'ref,opts*'
624
625
  task flag, [:commit] do |_, args|
625
626
  commit = commithead args.commit
626
- if commit
627
- args = args.extras
628
- else
629
- commit, opts = choice_commit(values: ['Options'])
630
- args = OptionPartition.strip(opts)
631
- end
627
+ args = if commit
628
+ args.extras
629
+ else
630
+ commit, opts = choice_commit(values: ['Options'])
631
+ OptionPartition.strip(opts)
632
+ end
632
633
  checkout(flag, args, commit: commit)
633
634
  end
634
635
  when :detach
@@ -755,7 +756,8 @@ module Squared
755
756
  when 'h', 'hard' then ['hard']
756
757
  when 's', 'soft' then ['soft']
757
758
  when 'n', 'N' then ['mixed', 'N']
758
- else ['mixed'] end)
759
+ else ['mixed']
760
+ end)
759
761
  end
760
762
  print_success if success?(reset(flag, args, commit: commit))
761
763
  end
@@ -804,28 +806,28 @@ module Squared
804
806
  when :branch
805
807
  format_desc action, flag, 'upstream,branch?=HEAD,opts*'
806
808
  task flag, [:upstream] do |_, args|
807
- if (upstream = args.upstream)
808
- args = args.extras
809
- else
810
- upstream, opts = choice_refs('Choose upstream branch', values: ['Options'])
811
- args = OptionPartition.strip(opts)
812
- end
809
+ args = if (upstream = args.upstream)
810
+ args.extras
811
+ else
812
+ upstream, opts = choice_refs('Choose upstream branch', values: ['Options'])
813
+ OptionPartition.strip(opts)
814
+ end
813
815
  rebase(flag, args, upstream: upstream)
814
816
  end
815
817
  when :onto
816
818
  format_desc action, flag, 'ref,upstream,branch?=HEAD'
817
819
  task flag, [:commit, :upstream, :branch] do |_, args|
818
820
  commit = commithead args.commit
819
- if commit
820
- upstream = param_guard(action, flag, args: args, key: :upstream)
821
- branch = args.branch
822
- args = []
823
- else
824
- commit = choice_refs 'Choose "onto" branch'
825
- target, opts = choice_commit(multiple: 2, values: ['Options'], reflog: false)
826
- branch, upstream = target
827
- args = OptionPartition.strip(opts)
828
- end
821
+ args = if commit
822
+ upstream = param_guard(action, flag, args: args, key: :upstream)
823
+ branch = args.branch
824
+ []
825
+ else
826
+ commit = choice_refs 'Choose "onto" branch'
827
+ target, opts = choice_commit(multiple: 2, values: ['Options'], reflog: false)
828
+ branch, upstream = target
829
+ OptionPartition.strip(opts)
830
+ end
829
831
  rebase(flag, args, commit: commit, upstream: upstream, branch: branch)
830
832
  end
831
833
  when :commit, :'no-commit'
@@ -889,13 +891,13 @@ module Squared
889
891
  format_desc action, flag, 'ref,opts*,pathspec*'
890
892
  task flag, [:commit] do |_, args|
891
893
  commit = commithead args.commit
892
- if commit
893
- args = args.extras
894
- else
895
- commit, opts, files = choice_commit(values: ['Options', ['Pathspec', true]])
896
- args = OptionPartition.strip(opts)
897
- files = files&.shellsplit
898
- end
894
+ args = if commit
895
+ args.extras
896
+ else
897
+ commit, opts, files = choice_commit(values: ['Options', ['Pathspec', true]])
898
+ files = files&.shellsplit
899
+ OptionPartition.strip(opts)
900
+ end
899
901
  restore(flag, args, commit: commit, files: files)
900
902
  end
901
903
  when :staged, :worktree
@@ -921,7 +923,8 @@ module Squared
921
923
  before = case flag
922
924
  when :blame then 'file'
923
925
  when :mv then 'source+,destination'
924
- when :revert then 'commit+' end
926
+ when :revert then 'commit+'
927
+ end
925
928
  format_desc(action, flag, 'opts*', before: before, after: case flag
926
929
  when :add
927
930
  'pathspec*,pattern*'
@@ -956,43 +959,9 @@ module Squared
956
959
  def pull(flag = nil, opts = [], sync: invoked_sync?('pull', flag), remote: nil, hint: nil)
957
960
  cmd, opts = git_session('pull', opts: opts)
958
961
  cmd << '--autostash' if option('autostash')
959
- case flag
960
- when :rebase
962
+ if flag == :rebase
961
963
  cmd << '--rebase'
962
- when :all
963
- unless git_spawn('status -s -z --untracked-files=all').empty?
964
- if confirm('Stash local changes? [Y/n] ', 'Y')
965
- git_spawn 'stash push --keep-index --quiet'
966
- elsif !(force = confirm('Force checkout? [y/N] ', 'N'))
967
- return
968
- end
969
- end
970
- op = OptionPartition.new(opts, OPT_GIT[:pull], cmd, project: self, no: OPT_GIT[:no][:pull])
971
- reg = if op.empty?
972
- []
973
- else
974
- opts = opts.reject { |val| op.extras.include?(val) }
975
- matchmap op
976
- end
977
- session_done op.target
978
- heads = []
979
- cur = nil
980
- foreachref('heads', format: '%(if)%(HEAD)%(then)* %(end)%(refname:short)').each do |line|
981
- line.chomp!
982
- cur ||= line.delete_prefix!('* ')
983
- heads << line if matchany?(line, reg)
984
- end
985
- raise_error('head not found', hint: 'for-each-ref') unless cur
986
- opts << 'ff-only' if opts.empty? && !option('ff-only', equals: '0')
987
- (heads.dup << cur).each_with_index do |branch, index|
988
- next unless (index < heads.size && cur != branch) || index == heads.size
989
-
990
- git_spawn 'switch --quiet', force && '--force', shell_quote(branch)
991
- pull(nil, opts, sync: false, hint: branch) if heads.include?(branch)
992
- end
993
- return
994
964
  else
995
- cmd << '--autostash' if flag == :autostash
996
965
  if (val = option('rebase', ignore: false))
997
966
  cmd << case val
998
967
  when '0', 'false'
@@ -1001,10 +970,47 @@ module Squared
1001
970
  VAL_GIT[:rebase][:value].include?(val) ? basic_option('rebase', val) : '--rebase'
1002
971
  end
1003
972
  end
973
+ case flag
974
+ when :all
975
+ unless git_spawn('status -s -z --untracked-files=all').empty?
976
+ if confirm('Stash local changes? [Y/n] ', 'Y')
977
+ git_spawn 'stash push --keep-index --quiet'
978
+ elsif !(force = confirm('Force checkout? [y/N] ', 'N'))
979
+ return
980
+ end
981
+ printsucc
982
+ end
983
+ op = OptionPartition.new(opts, OPT_GIT[:pull], cmd, project: self, no: OPT_GIT[:no][:pull])
984
+ reg = if op.empty?
985
+ []
986
+ else
987
+ opts = op.uniq(opts)
988
+ matchmap op
989
+ end
990
+ session_done op.target
991
+ heads = []
992
+ cur = nil
993
+ foreachref('heads', format: '%(if)%(HEAD)%(then)* %(end)%(refname:short)').each do |line|
994
+ line.chomp!
995
+ cur ||= line.delete_prefix!('* ')
996
+ heads << line if matchany?(line, reg)
997
+ end
998
+ raise_error('head not found', hint: 'for-each-ref') unless cur
999
+ opts << 'ff-only' if opts.empty? && !option('ff-only', equals: '0')
1000
+ (heads.dup << cur).each_with_index do |branch, index|
1001
+ next unless (index < heads.size && cur != branch) || index == heads.size
1002
+
1003
+ git_spawn 'switch --quiet', force && '--force', shell_quote(branch)
1004
+ pull(nil, opts, sync: false, hint: branch) if heads.include?(branch)
1005
+ end
1006
+ return
1007
+ when :autostash
1008
+ cmd << '--autostash'
1009
+ end
1004
1010
  end
1005
1011
  append_pull(opts, OPT_GIT[:pull] + OPT_GIT[:fetch][:pull],
1006
1012
  no: OPT_GIT[:no][:pull] + OPT_GIT[:no][:fetch][:pull], remote: remote, flag: flag, from: :pull)
1007
- source(sync: sync, sub: if verbose
1013
+ source(sync: sync, sub: if stdout?
1008
1014
  [
1009
1015
  { pat: /^(.+)(\|\s+\d+\s+)([^-]*)(-+)(.*)$/, styles: color(:red), index: 4 },
1010
1016
  { pat: /^(.+)(\|\s+\d+\s+)(\++)(.*)$/, styles: color(:green), index: 3 }
@@ -1033,6 +1039,10 @@ module Squared
1033
1039
  cmd << upstream
1034
1040
  append_head branch
1035
1041
  else
1042
+ unless gitpath('REBASE_HEAD').exist?
1043
+ puts log_message(Logger::INFO, name, 'no rebase in progress', hint: command) if stdout?
1044
+ return
1045
+ end
1036
1046
  return unless VAL_GIT[:rebase][:send].include?(command)
1037
1047
 
1038
1048
  cmd << "--#{command}"
@@ -1092,6 +1102,7 @@ module Squared
1092
1102
  op = OptionPartition.new(opts, list, cmd, project: self, no: no, first: flag == :push ? matchpathspec : nil)
1093
1103
  case flag
1094
1104
  when :push
1105
+ op.append?('message', readline('Enter message', force: true), force: true) if op.remove(':')
1095
1106
  append_pathspec op.extras
1096
1107
  when :pop, :apply, :drop, :branch
1097
1108
  if op.remove(':')
@@ -1157,7 +1168,7 @@ module Squared
1157
1168
  end
1158
1169
  append_pathspec
1159
1170
  end
1160
- if verbose
1171
+ if stdout?
1161
1172
  r = color(:red)
1162
1173
  g = color(:green)
1163
1174
  sub = if session_arg?('short')
@@ -1210,7 +1221,7 @@ module Squared
1210
1221
  if (cur = workspace.rev_entry(name)) && cur['revision'] == sha && !env('REVBUILD_FORCE')
1211
1222
  files = status_digest(*args, **kwargs)
1212
1223
  if cur['files'].size == files.size && cur['files'].find { |key, val| files[key] != val }.nil?
1213
- if verbose
1224
+ if stdout?
1214
1225
  if (since = workspace.rev_timesince(name, 'build'))
1215
1226
  puts log_message(Logger::INFO, name, 'no changes', subject: 'revbuild', hint: "#{since} ago")
1216
1227
  else
@@ -1364,15 +1375,14 @@ module Squared
1364
1375
  op << '--no-index'
1365
1376
  append_pathspec(refs, parent: true)
1366
1377
  else
1378
+ op << '--merge-base' if option('merge-base')
1367
1379
  case flag
1368
1380
  when :view
1369
- op << '--merge-base' if option('merge-base')
1370
1381
  op.merge(range)
1371
1382
  when :between, :contain
1372
1383
  op.delete('--merge-base')
1373
1384
  op.add_quote(range.join(flag == :between ? '..' : '...'))
1374
1385
  else
1375
- op << '--merge-base' if option('merge-base')
1376
1386
  op.add_quote(branch) if branch
1377
1387
  if !index.empty?
1378
1388
  if op.arg?('cached')
@@ -1428,16 +1438,16 @@ module Squared
1428
1438
  branch, origin, hint = line.split('...')
1429
1439
  if hint && !hint.match?(/^\[(\D+0,\D+0)\]$/)
1430
1440
  raise_error('work tree is not usable', hint: hint[1..-2])
1431
- elsif origin.empty?
1441
+ elsif !origin || origin.empty?
1432
1442
  return nil if pass
1433
1443
  break if dryrun
1434
1444
 
1435
1445
  unless (origin = option('upstream', prefix: 'git', ignore: false))
1436
1446
  if (origin = choice_refs('Choose an upstream', 'remotes', attempts: 1, force: false))
1437
1447
  git_spawn 'branch', quote_option('set-upstream-to', origin)
1438
- else
1439
- origin = readline('Enter an upstream', force: true)
1448
+ break
1440
1449
  end
1450
+ origin = readline('Enter an upstream', force: true)
1441
1451
  end
1442
1452
  raise_error('missing remote name', hint: origin) unless origin.include?('/')
1443
1453
  upstream = true
@@ -1472,6 +1482,7 @@ module Squared
1472
1482
 
1473
1483
  def merge(flag, opts = [], command: nil, branch: nil)
1474
1484
  cmd, opts = git_session('merge', opts: opts)
1485
+ display = false
1475
1486
  case flag
1476
1487
  when :commit, :'no-commit'
1477
1488
  op = OptionPartition.new(opts, OPT_GIT[:merge], cmd, project: self, no: OPT_GIT[:no][:merge])
@@ -1484,11 +1495,16 @@ module Squared
1484
1495
  append_commit(*op.extras)
1485
1496
  end
1486
1497
  else
1498
+ unless gitpath('MERGE_HEAD').exist?
1499
+ puts log_message(Logger::INFO, name, 'no merge in progress', hint: command) if stdout?
1500
+ return
1501
+ end
1487
1502
  return unless VAL_GIT[:merge][:send].include?(command)
1488
1503
 
1489
1504
  cmd << "--#{command}"
1505
+ display = command == 'abort'
1490
1506
  end
1491
- source
1507
+ print_success if success?(source, display)
1492
1508
  end
1493
1509
 
1494
1510
  def branch(flag = nil, opts = [], refs: [], ref: nil, target: nil, remote: nil)
@@ -1525,10 +1541,8 @@ module Squared
1525
1541
  end
1526
1542
  force, list = refs.partition { |val| val.match?(/^[~^]/) }
1527
1543
  force.each do |val|
1528
- dr = val[0, 2]
1529
- d = dr.include?('^') ? '-D' : '-d'
1530
- r = '-r' if dr.include?('~')
1531
- source git_output('branch', d, r, shell_quote(val.sub(/^[~^]+/, '')))
1544
+ r = '-r' if val.delete!('~')
1545
+ source git_output('branch', val.delete!('^') ? '-D' : '-d', r, shell_quote(val))
1532
1546
  end
1533
1547
  return if list.empty?
1534
1548
 
@@ -1536,8 +1550,9 @@ module Squared
1536
1550
  append_value list
1537
1551
  remote = nil
1538
1552
  when :move, :copy
1539
- flag = "-#{flag.to_s[0]}"
1540
- cmd << (option('force', 'f') ? flag.upcase : flag)
1553
+ s = "-#{flag.to_s[0]}"
1554
+ s.upcase! if option('force', 'f')
1555
+ cmd << s
1541
1556
  refs.compact.each { |val| cmd << shell_quote(val) }
1542
1557
  stdout = true
1543
1558
  when :current
@@ -1557,12 +1572,12 @@ module Squared
1557
1572
  list_result(ret, 'branches', from: from)
1558
1573
  return
1559
1574
  else
1560
- head = git_spawn('rev-parse --abbrev-ref HEAD').chomp
1561
- if head.empty?
1575
+ if (head = git_spawn('rev-parse --abbrev-ref HEAD').chomp).empty?
1562
1576
  ret = 0
1563
1577
  else
1564
1578
  git_spawn 'fetch --all --prune --quiet' if option('sync')
1565
- out, banner, from = source(cmd << '-vv --no-abbrev --list', io: true)
1579
+ cmd << '-vv --no-abbrev --list'
1580
+ out, banner, from = source(io: true)
1566
1581
  ret = write_lines(out, grep: [/^\*\s+#{Regexp.escape(head)}\s/], banner: banner, first: true) do |line|
1567
1582
  next line if stdin?
1568
1583
 
@@ -1633,10 +1648,13 @@ module Squared
1633
1648
  op = OptionPartition.new(opts, OPT_GIT[:submodule].fetch(flag, []), cmd, project: self)
1634
1649
  case flag
1635
1650
  when :branch, :url
1651
+ op.adjoin("set-#{flag}")
1636
1652
  op << '--'
1637
1653
  op.add_path(path) if path
1638
1654
  op.add_quote(url) if url
1639
1655
  else
1656
+ op.adjoin(flag)
1657
+ op << '--recursive' if option('recursive', 'r')
1640
1658
  op.splice(path: true)
1641
1659
  end
1642
1660
  source
@@ -1661,19 +1679,15 @@ module Squared
1661
1679
  source(banner: false)
1662
1680
  return
1663
1681
  when :oneline
1664
- format = 'oneline'
1682
+ format = flag.to_s
1665
1683
  end
1666
- if format
1667
- case (val = format.downcase)
1668
- when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
1669
- cmd << basic_option('format', val)
1670
- else
1671
- if format.match?(/^t?format:/) || format.include?('%')
1672
- cmd << quote_option('pretty', format)
1673
- else
1674
- opts << format
1675
- end
1676
- end
1684
+ case format
1685
+ when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
1686
+ cmd << basic_option('format', format)
1687
+ when /(?:^t?format:|%)/
1688
+ cmd << quote_option('pretty', format)
1689
+ else
1690
+ opts << format if format
1677
1691
  end
1678
1692
  op = OptionPartition.new(opts, OPT_GIT[:show] + OPT_GIT[:diff][:show] + OPT_GIT[:log][:diff], cmd,
1679
1693
  project: self,
@@ -1730,7 +1744,8 @@ module Squared
1730
1744
  project: self, no: OPT_GIT[:no][flag], first: case flag
1731
1745
  when :blame, :revert
1732
1746
  nil
1733
- else matchpathspec end)
1747
+ else matchpathspec
1748
+ end)
1734
1749
  case flag
1735
1750
  when :blame
1736
1751
  raise_error 'no file found' unless (n = op.index { |s| (path + s).file? })
@@ -1765,8 +1780,7 @@ module Squared
1765
1780
  end
1766
1781
  return source(git_session('status -s'), banner: false) unless append_pathspec(op.extras)
1767
1782
 
1768
- verbose = flag == :add && !op.arg?('verbose')
1769
- print_success if success?(source) && verbose
1783
+ print_success if success?(source, flag == :add && !op.arg?('verbose'))
1770
1784
  return
1771
1785
  when :mv
1772
1786
  refs = projectmap op.extras
@@ -1793,7 +1807,7 @@ module Squared
1793
1807
  private
1794
1808
 
1795
1809
  def source(cmd = @session, exception: true, io: false, sync: true, stdout: false, stderr: false, banner: true,
1796
- multiple: false, hint: nil, from: nil, **kwargs)
1810
+ multiple: false, hint: nil, from: nil, send: :system, **kwargs)
1797
1811
  cmd = cmd.target if cmd.is_a?(OptionPartition)
1798
1812
  if io && banner == false
1799
1813
  from = nil
@@ -1801,7 +1815,7 @@ module Squared
1801
1815
  else
1802
1816
  banner = nil if banner && (multiple || !banner?)
1803
1817
  if cmd.respond_to?(:done)
1804
- if from.nil? && (from = cmd.drop(1).find { |val| val.match?(/\A[a-z]{1,2}[a-z\-]*\z/) })
1818
+ if from.nil? && (from = cmd.drop(1).find { |val| val.match?(/\A[a-z]{1,2}[a-z-]*\z/) })
1805
1819
  from = :"git:#{from}"
1806
1820
  end
1807
1821
  banner &&= cmd.temp { |val| val.start_with?('--work-tree') || val.start_with?('--git-dir') }
@@ -1833,7 +1847,7 @@ module Squared
1833
1847
  end
1834
1848
  elsif !kwargs[:sub] && (sync || (!exception && !stderr))
1835
1849
  print_item banner unless multiple
1836
- ret = shell(cmd, exception: exception)
1850
+ ret = shell(cmd, name: send, exception: exception)
1837
1851
  else
1838
1852
  require 'open3'
1839
1853
  if stderr
@@ -1891,7 +1905,7 @@ module Squared
1891
1905
  def list_result(size, type, grep: [], action: 'found', from: nil)
1892
1906
  if size == 0
1893
1907
  puts empty_status("No #{type} were #{action}", 'grep', grep.join(', '))
1894
- elsif verbose
1908
+ elsif stdout?
1895
1909
  styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
1896
1910
  styles << :bold if styles.size <= 1
1897
1911
  puts print_footer("#{size} #{size == 1 ? type.sub(/(?:(?<!l)e)?s\z/, '') : type}",
@@ -1966,11 +1980,9 @@ module Squared
1966
1980
  when 'rebase'
1967
1981
  op << basic_option($1, $2) if VAL_GIT[:rebase][:value].include?($2)
1968
1982
  when 'shallow-since'
1969
- next unless (val = Date.parse($2))
1970
-
1971
- op << quote_option($1, val.strftime('%F %T'))
1983
+ op.append?($1) { Date.parse($2)&.strftime('%F %T') }
1972
1984
  when 'recurse-submodules'
1973
- op << basic_option($1, $2) unless op.arg?('recurse-submodules')
1985
+ op.append?($1, $2, type: :basic)
1974
1986
  when 'refspec'
1975
1987
  refspec << shell_escape($2, quote: true)
1976
1988
  end
@@ -1980,7 +1992,7 @@ module Squared
1980
1992
  op.errors << opt
1981
1993
  end
1982
1994
  end
1983
- op << '--verbose' if (flag || from == :fetch) && verbose && !op.arg?('quiet')
1995
+ op << '--verbose' if (flag || from == :fetch) && stdout? && !op.arg?('quiet')
1984
1996
  if remote
1985
1997
  op.append(remote, delim: true)
1986
1998
  if (val = option('refspec', target: target, strict: true))
@@ -1993,7 +2005,7 @@ module Squared
1993
2005
  op.swap.merge(op.map! { |opt| shell_escape(opt, quote: true) })
1994
2006
  return
1995
2007
  elsif option('all')
1996
- cmd << '--all'
2008
+ op << '--all'
1997
2009
  end
1998
2010
  op.clear(errors: true, subject: flag.to_s) if flag
1999
2011
  end
@@ -2083,8 +2095,17 @@ module Squared
2083
2095
  git_session(*cmd, main: false, options: false, **kwargs)
2084
2096
  end
2085
2097
 
2086
- def git_spawn(*cmd, stdout: true)
2087
- source(cmd.first.is_a?(Set) ? cmd.first : git_output(*cmd), io: true, banner: false, stdout: stdout)
2098
+ def git_spawn(*cmd, exception: true, io: true, sync: true, stdout: true, banner: false, **kwargs)
2099
+ kwargs[:send] = if sync
2100
+ :system
2101
+ else
2102
+ exception = false
2103
+ io = false
2104
+ stdout = false
2105
+ :spawn
2106
+ end
2107
+ source(cmd.first.is_a?(Set) ? cmd.first : git_output(*cmd), exception: exception, io: io, sync: sync,
2108
+ stdout: stdout, banner: banner, **kwargs)
2088
2109
  end
2089
2110
 
2090
2111
  def dryrun?(*, target: @session, **)
@@ -2099,8 +2120,8 @@ module Squared
2099
2120
  target.include?('--quiet') || (target.include?('-q') && stripext(target.first) == 'git')
2100
2121
  end
2101
2122
 
2102
- def gitpath
2103
- path + '.git'
2123
+ def gitpath(*args)
2124
+ path.join('.git', *args)
2104
2125
  end
2105
2126
 
2106
2127
  def repotrack(origin, branch, quote: true)
@@ -657,10 +657,10 @@ module Squared
657
657
  return
658
658
  end
659
659
  cmd = session 'npm', 'publish'
660
- cmd << basic_option('otp', otp) if otp &&= option('otp')
661
- cmd << basic_option('tag', tag) if tag &&= option('tag')
662
- cmd << basic_option('access', access) if access &&= option('access')
663
- dryrun &&= dryrun?('npm')
660
+ cmd << basic_option('otp', otp) if otp ||= option('otp')
661
+ cmd << basic_option('tag', tag) if tag ||= option('tag')
662
+ cmd << basic_option('access', access) if access ||= option('access')
663
+ dryrun ||= dryrun?('npm')
664
664
  if dryrun
665
665
  cmd << '--dry-run'
666
666
  else
@@ -671,13 +671,12 @@ module Squared
671
671
  run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(npmname, styles: theme[:active])}")
672
672
  else
673
673
  on :first, from
674
- pwd_set(from: :publish, dryrun: dryrun) do
674
+ pwd_set(from: from, dryrun: dryrun) do
675
675
  require 'open3'
676
- banner = format_banner(cmd.to_s)
676
+ banner = format_banner cmd.to_s
677
677
  Open3.popen2e(cmd.done) do |_, out|
678
- write_lines(out, banner: banner, sub: npmnotice + [
679
- { pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2 }
680
- ])
678
+ write_lines(out, sub: npmnotice + [pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2],
679
+ banner: banner)
681
680
  end
682
681
  end
683
682
  on :last, from
@@ -759,8 +758,8 @@ module Squared
759
758
  seg[4] &&= seg[4].succ
760
759
  else
761
760
  seg[2] = seg[2].succ
761
+ seg[4] &&= '0'
762
762
  end
763
- seg[4] = '0'
764
763
  when :patch
765
764
  seg[4] &&= seg[4].succ
766
765
  end
@@ -775,15 +774,15 @@ module Squared
775
774
  log.info "bump version #{cur} to #{val} (#{flag})"
776
775
  on :first, :bump
777
776
  end
778
- if verbose
777
+ if stdin?
778
+ puts val
779
+ elsif verbose
779
780
  major = flag == :major
780
781
  emphasize("version: #{val}", title: name, border: borderstyle, sub: [
781
782
  headerstyle,
782
783
  { pat: /\A(version:)( )(\S+)(.*)\z/, styles: color(major ? :green : :yellow), index: 3 },
783
784
  { pat: /\A(version:)(.*)\z/, styles: theme[major ? :major : :active] }
784
785
  ])
785
- elsif stdin?
786
- puts val
787
786
  end
788
787
  on :last, :bump unless dryrun?
789
788
  else
@@ -800,7 +799,7 @@ module Squared
800
799
  cmd = session dependbin, 'pack'
801
800
  if dependtype(:yarn) > 1
802
801
  op = OptionPartition.new(opts, OPT_BERRY[:pack], cmd, project: self)
803
- op << quote_option('out', Pathname.pwd + "#{project}-#{version}.tgz") unless op.arg?('out')
802
+ op.append?('out', Pathname.pwd + "#{project}-#{version}.tgz")
804
803
  else
805
804
  op = OptionPartition.new(opts, pnpm? ? OPT_PNPM[:pack] : OPT_NPM[:pack] + OPT_NPM[:common], cmd,
806
805
  project: self)
@@ -815,7 +814,7 @@ module Squared
815
814
  end
816
815
  end
817
816
  end
818
- op << quote_option('pack-destination', Dir.pwd) unless op.arg?('pack-destination')
817
+ op.append?('pack-destination', Dir.pwd)
819
818
  end
820
819
  op.clear
821
820
  run(from: :pack)
@@ -936,6 +935,10 @@ module Squared
936
935
  read_packagemanager :name
937
936
  end
938
937
 
938
+ def scripts
939
+ @scripts ||= read_scripts.to_h
940
+ end
941
+
939
942
  private
940
943
 
941
944
  def read_packagemanager(key = nil, version: nil, update: false)
@@ -1004,10 +1007,6 @@ module Squared
1004
1007
  end
1005
1008
  end
1006
1009
 
1007
- def dryrun?(prefix = dependbin, **)
1008
- super || !option('dry-run', prefix: prefix).nil?
1009
- end
1010
-
1011
1010
  def dependbin
1012
1011
  if yarn?
1013
1012
  'yarn'
@@ -1032,6 +1031,10 @@ module Squared
1032
1031
  { pat: /^(npm )(.+)$/, styles: :bold }
1033
1032
  ]
1034
1033
  end
1034
+
1035
+ def dryrun?(prefix = dependbin, **)
1036
+ super || !option('dry-run', prefix: prefix).nil?
1037
+ end
1035
1038
  end
1036
1039
 
1037
1040
  Application.implement Node
@@ -132,7 +132,7 @@ module Squared
132
132
  format_desc action, nil, "script+|#{indexchar}index+|#,pattern*"
133
133
  task action, [:command] do |_, args|
134
134
  found = 0
135
- ['tool.poetry.scripts', 'tool.pdm.scripts', 'project.scripts'].each_with_index do |table, index|
135
+ %w[tool.poetry.scripts tool.pdm.scripts project.scripts].each_with_index do |table, index|
136
136
  next if (list = read_pyproject(table)).empty?
137
137
 
138
138
  if args.command == '#'
@@ -786,7 +786,7 @@ module Squared
786
786
  end
787
787
  @pyproject[table] = ret
788
788
  end
789
- return ret.find { |val| val[0] == key }&.last if key
789
+ return ret.find { |val| val.first == key }&.last if key
790
790
 
791
791
  ret
792
792
  end