squared 0.4.3 → 0.4.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -0
- data/README.ruby.md +130 -61
- data/lib/squared/common/format.rb +2 -6
- data/lib/squared/common/shell.rb +2 -1
- data/lib/squared/common/utils.rb +8 -5
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +10 -1
- data/lib/squared/workspace/project/base.rb +114 -46
- data/lib/squared/workspace/project/docker.rb +125 -58
- data/lib/squared/workspace/project/git.rb +59 -66
- data/lib/squared/workspace/project/node.rb +25 -27
- data/lib/squared/workspace/project/python.rb +213 -79
- data/lib/squared/workspace/project/ruby.rb +96 -40
- data/lib/squared/workspace/repo.rb +1 -1
- metadata +2 -2
@@ -145,16 +145,14 @@ module Squared
|
|
145
145
|
|
146
146
|
module Project
|
147
147
|
class Git < Base
|
148
|
-
include Prompt
|
149
|
-
|
150
148
|
OPT_GIT = {
|
151
|
-
common: %w[bare
|
149
|
+
common: %w[bare paginate no-pager glob-pathspecs icase-pathspecs literal-pathspecs no-optional-locks
|
152
150
|
no-replace-objects noglob-pathspecs c=q config-env=q exec-path=p namespace=p].freeze,
|
153
151
|
branch: %w[a|all create-reflog i|ignore-case q|quiet r|remotes v|verbose abbrev=i color=b column=b
|
154
152
|
contains=b format=q merged=b no-contains=b no-merged=b points-at=e u|set-upstream-to=e sort=q
|
155
153
|
t|track=b].freeze,
|
156
154
|
checkout: %w[l d|detach f|force ignore-other-worktrees ignore-skip-worktree-bits m|merge p|patch
|
157
|
-
pathspec-file-nul q
|
155
|
+
pathspec-file-nul q|quiet orphan=e ours theirs conflict=b pathspec-from-file=p
|
158
156
|
t|track=b].freeze,
|
159
157
|
clean: %w[d x X f|force i|interactive n|dry-run q|quiet e|exlcude=q].freeze,
|
160
158
|
diff: {
|
@@ -309,25 +307,26 @@ module Squared
|
|
309
307
|
end
|
310
308
|
end
|
311
309
|
|
312
|
-
|
310
|
+
subtasks({
|
313
311
|
'branch' => %i[create set delete move copy list edit current].freeze,
|
314
312
|
'checkout' => %i[commit branch track detach path].freeze,
|
315
313
|
'commit' => %i[add all amend amend-orig].freeze,
|
316
314
|
'diff' => %i[head branch files view between contain].freeze,
|
317
315
|
'fetch' => %i[origin remote].freeze,
|
318
316
|
'files' => %i[cached modified deleted others ignored].freeze,
|
319
|
-
'git' => %i[clean mv
|
317
|
+
'git' => %i[clean mv revert rm].freeze,
|
320
318
|
'log' => %i[view between contain].freeze,
|
321
319
|
'merge' => %i[commit no-commit send].freeze,
|
322
320
|
'pull' => %i[origin remote].freeze,
|
323
321
|
'rebase' => %i[branch onto send].freeze,
|
324
322
|
'refs' => %i[heads tags remote].freeze,
|
325
323
|
'reset' => %i[commit index patch mode].freeze,
|
324
|
+
'restore' => %i[staged worktree].freeze,
|
326
325
|
'rev' => %i[commit branch output parseopt build].freeze,
|
327
326
|
'show' => %i[format oneline textconv].freeze,
|
328
327
|
'stash' => %i[push pop apply drop clear list].freeze,
|
329
328
|
'tag' => %i[add delete list].freeze
|
330
|
-
}
|
329
|
+
})
|
331
330
|
|
332
331
|
def initialize(*, **)
|
333
332
|
super
|
@@ -654,7 +653,7 @@ module Squared
|
|
654
653
|
format_desc action, flag, 'remote,opts*,pattern*'
|
655
654
|
task flag, [:remote] do |_, args|
|
656
655
|
remote = param_guard(action, flag, args: args, key: :remote)
|
657
|
-
ls_remote(flag, args.
|
656
|
+
ls_remote(flag, args.extras, remote: remote)
|
658
657
|
end
|
659
658
|
else
|
660
659
|
format_desc action, flag, 'opts*,pattern*'
|
@@ -662,7 +661,7 @@ module Squared
|
|
662
661
|
__send__(action == 'refs' ? :ls_remote : :ls_files, flag, args.to_a)
|
663
662
|
end
|
664
663
|
end
|
665
|
-
when 'git'
|
664
|
+
when 'restore', 'git'
|
666
665
|
format_desc(action, flag, 'opts*', before: case flag
|
667
666
|
when :rm
|
668
667
|
'source+,destination'
|
@@ -672,7 +671,7 @@ module Squared
|
|
672
671
|
'pathspec*'
|
673
672
|
end)
|
674
673
|
task flag do |_, args|
|
675
|
-
|
674
|
+
__send__(action, flag, args.to_a)
|
676
675
|
end
|
677
676
|
end
|
678
677
|
end
|
@@ -733,7 +732,7 @@ module Squared
|
|
733
732
|
append_value(branch, delim: true)
|
734
733
|
else
|
735
734
|
append_value([branch.pop, branch.pop].reverse, delim: true)
|
736
|
-
option_clear
|
735
|
+
option_clear(branch, pass: false)
|
737
736
|
end
|
738
737
|
when :onto
|
739
738
|
return unless upstream
|
@@ -859,7 +858,7 @@ module Squared
|
|
859
858
|
end
|
860
859
|
return
|
861
860
|
end
|
862
|
-
sha =
|
861
|
+
sha = git_spawn('rev-parse --verify HEAD').first.to_s.chomp
|
863
862
|
return if sha.empty?
|
864
863
|
|
865
864
|
args = []
|
@@ -867,7 +866,7 @@ module Squared
|
|
867
866
|
case flag
|
868
867
|
when :build
|
869
868
|
opts = option_sanitize(opts, OPT_GIT[:status], target: args).first
|
870
|
-
option_clear
|
869
|
+
option_clear(opts, append: true)
|
871
870
|
else
|
872
871
|
args << basic_option('untracked-files', flag) if (flag = option('untracked-files', prefix: 'git'))
|
873
872
|
args << basic_option('ignore-submodules', flag) if (flag = option('ignore-submodules', prefix: 'git'))
|
@@ -902,13 +901,13 @@ module Squared
|
|
902
901
|
cmd, opts = git_session('reset', opts: opts)
|
903
902
|
case flag
|
904
903
|
when :commit, :index
|
905
|
-
|
904
|
+
files = option_sanitize(opts, OPT_GIT[:reset] + VAL_GIT[:reset], no: OPT_GIT[:no][:reset]).first
|
906
905
|
if flag == :commit
|
907
906
|
append_value(commit, delim: true)
|
908
|
-
option_clear
|
907
|
+
option_clear(files, pass: false)
|
909
908
|
ref = false
|
910
909
|
else
|
911
|
-
(refs ||= []).concat(
|
910
|
+
(refs ||= []).concat(files)
|
912
911
|
end
|
913
912
|
when :mode
|
914
913
|
return unless VAL_GIT[:reset].include?(mode)
|
@@ -925,7 +924,7 @@ module Squared
|
|
925
924
|
end
|
926
925
|
unless ref == false
|
927
926
|
append_commit(ref, head: true)
|
928
|
-
append_pathspec
|
927
|
+
append_pathspec(refs, pass: false) if refs
|
929
928
|
end
|
930
929
|
source
|
931
930
|
end
|
@@ -937,12 +936,7 @@ module Squared
|
|
937
936
|
when :branch
|
938
937
|
cmd << '--detach' if detach == 'd' || option('detach')
|
939
938
|
append_option('track', equals: true)
|
940
|
-
cmd <<
|
941
|
-
shell_option(create, branch)
|
942
|
-
else
|
943
|
-
branch
|
944
|
-
end
|
945
|
-
cmd << commit
|
939
|
+
cmd << (create ? shell_option(create, branch) : branch) << commit
|
946
940
|
when :track
|
947
941
|
if branch
|
948
942
|
if branch.start_with?('^')
|
@@ -955,13 +949,13 @@ module Squared
|
|
955
949
|
when :detach
|
956
950
|
cmd << '--detach' << commit
|
957
951
|
else
|
958
|
-
|
952
|
+
refs = option_sanitize(opts, OPT_GIT[:checkout], no: OPT_GIT[:no][:checkout]).first
|
959
953
|
if flag == :commit
|
960
954
|
append_value(commit, delim: true)
|
961
|
-
option_clear
|
955
|
+
option_clear(refs, pass: false)
|
962
956
|
else
|
963
957
|
append_head
|
964
|
-
append_pathspec
|
958
|
+
append_pathspec refs
|
965
959
|
end
|
966
960
|
end
|
967
961
|
source
|
@@ -1044,7 +1038,7 @@ module Squared
|
|
1044
1038
|
else
|
1045
1039
|
cmd.merge(index)
|
1046
1040
|
end
|
1047
|
-
elsif (n = option('index'))
|
1041
|
+
elsif (n = option('index', ignore: false))
|
1048
1042
|
cmd << "HEAD~#{n}"
|
1049
1043
|
end
|
1050
1044
|
end
|
@@ -1071,8 +1065,8 @@ module Squared
|
|
1071
1065
|
origin = nil
|
1072
1066
|
branch = nil
|
1073
1067
|
upstream = nil
|
1074
|
-
|
1075
|
-
|
1068
|
+
git_spawn 'fetch --no-tags --quiet'
|
1069
|
+
git_spawn('branch -vv --list', stdout: false).first.each do |val|
|
1076
1070
|
next unless (r = /^\*\s(\S+)\s+(\h+)(?:\s\[(.+?)(?=\]\s)\])?\s/.match(val))
|
1077
1071
|
|
1078
1072
|
branch = r[1]
|
@@ -1080,7 +1074,7 @@ module Squared
|
|
1080
1074
|
origin = r[3][%r{^(.+)/#{Regexp.escape(branch)}$}, 1]
|
1081
1075
|
else
|
1082
1076
|
unless (origin = option('repository', prefix: 'git', ignore: false))
|
1083
|
-
out =
|
1077
|
+
out = git_spawn('log -n1 --format=%h%d').first
|
1084
1078
|
if out =~ /^#{r[2]} \(HEAD -> #{Regexp.escape(branch)}, (.+?)\)$/
|
1085
1079
|
split_escape($1).each do |s|
|
1086
1080
|
next unless s.end_with?("/#{branch}")
|
@@ -1103,7 +1097,7 @@ module Squared
|
|
1103
1097
|
end
|
1104
1098
|
if message
|
1105
1099
|
append_message message
|
1106
|
-
elsif flag == :'amend-orig' || option('
|
1100
|
+
elsif flag == :'amend-orig' || option('edit', equals: '0')
|
1107
1101
|
cmd << '--no-edit'
|
1108
1102
|
end
|
1109
1103
|
a = git_output 'add', '--verbose'
|
@@ -1186,16 +1180,9 @@ module Squared
|
|
1186
1180
|
when :current
|
1187
1181
|
cmd << '--show-current'
|
1188
1182
|
when :list
|
1189
|
-
|
1190
|
-
option_sanitize(opts, OPT_GIT[:branch], no: OPT_GIT[:no][:branch]).first.each do |opt|
|
1191
|
-
if opt =~ /^(v+)$/
|
1192
|
-
cmd << "-#{$1}"
|
1193
|
-
else
|
1194
|
-
grep << opt
|
1195
|
-
end
|
1196
|
-
end
|
1183
|
+
opts = option_sanitize(opts, OPT_GIT[:branch], no: OPT_GIT[:no][:branch], single: /^v+$/).first
|
1197
1184
|
cmd << '--list'
|
1198
|
-
|
1185
|
+
opts.each { |val| cmd << shell_quote(val) }
|
1199
1186
|
out, banner, from = source(io: true)
|
1200
1187
|
print_item banner
|
1201
1188
|
ret = write_lines(out, sub: [
|
@@ -1205,10 +1192,11 @@ module Squared
|
|
1205
1192
|
list_result(ret, 'branches', from: from)
|
1206
1193
|
return
|
1207
1194
|
else
|
1208
|
-
head =
|
1195
|
+
head = git_spawn('rev-parse --abbrev-ref HEAD').first.chomp
|
1209
1196
|
if head.empty?
|
1210
1197
|
ret = 0
|
1211
1198
|
else
|
1199
|
+
git_spawn 'fetch --all --prune --quiet' if option('sync')
|
1212
1200
|
out, banner, from = source(cmd << '-vv --no-abbrev --list', io: true)
|
1213
1201
|
ret = write_lines(out, grep: /^\*\s+#{Regexp.escape(head)}\s/, banner: banner, first: true) do |line|
|
1214
1202
|
next line if stdin?
|
@@ -1240,6 +1228,13 @@ module Squared
|
|
1240
1228
|
source(stdout: stdout)
|
1241
1229
|
end
|
1242
1230
|
|
1231
|
+
def restore(flag, opts = [])
|
1232
|
+
opts = git_session('restore', "--#{flag}", opts: opts).last
|
1233
|
+
refs = option_sanitize(opts, OPT_GIT[:restore], no: OPT_GIT[:no][:restore]).first
|
1234
|
+
append_pathspec(refs, pass: false)
|
1235
|
+
source(sync: false, stderr: true)
|
1236
|
+
end
|
1237
|
+
|
1243
1238
|
def show(flag, opts = [], format: nil, files: [])
|
1244
1239
|
cmd, opts = git_session('show', opts: opts)
|
1245
1240
|
case flag
|
@@ -1321,23 +1316,17 @@ module Squared
|
|
1321
1316
|
def git(flag, opts = [])
|
1322
1317
|
cmd, opts = git_session(flag, opts: opts)
|
1323
1318
|
refs = option_sanitize(opts, OPT_GIT[flag], no: OPT_GIT[:no][flag]).first
|
1324
|
-
refs = projectmap(refs) unless flag == :revert
|
1325
1319
|
sync = false
|
1326
1320
|
stderr = true
|
1327
1321
|
case flag
|
1328
1322
|
when :clean
|
1323
|
+
refs = projectmap(refs)
|
1329
1324
|
unless refs.empty?
|
1330
1325
|
cmd << '--'
|
1331
1326
|
cmd.merge(refs)
|
1332
1327
|
end
|
1333
1328
|
sync = true
|
1334
1329
|
stderr = false
|
1335
|
-
when :restore
|
1336
|
-
if session_arg?('p', 'patch')
|
1337
|
-
option_clear refs
|
1338
|
-
else
|
1339
|
-
append_pathspec(refs, expect: true)
|
1340
|
-
end
|
1341
1330
|
when :revert
|
1342
1331
|
if VAL_GIT[:rebase][:send].any? { |val| session_arg?(val) }
|
1343
1332
|
option_clear refs
|
@@ -1347,6 +1336,7 @@ module Squared
|
|
1347
1336
|
append_commit(*refs)
|
1348
1337
|
end
|
1349
1338
|
when :mv
|
1339
|
+
refs = projectmap(refs)
|
1350
1340
|
raise_error 'no source/destination' unless refs.size > 1
|
1351
1341
|
cmd.merge(refs)
|
1352
1342
|
when :rm
|
@@ -1463,7 +1453,7 @@ module Squared
|
|
1463
1453
|
if size > 0
|
1464
1454
|
styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
|
1465
1455
|
styles << :bold if styles.size <= 1
|
1466
|
-
puts print_footer("#{size} #{size == 1 ? type.sub(/e?s\z/, '') : type}",
|
1456
|
+
puts print_footer("#{size} #{size == 1 ? type.sub(/(?:(?<!l)e)?s\z/, '') : type}",
|
1467
1457
|
sub: { pat: /\A(\d+)(.+)\z/, styles: styles })
|
1468
1458
|
else
|
1469
1459
|
puts empty_status("No #{type} were #{action}", 'grep', grep.is_a?(Array) ? case grep.size
|
@@ -1481,17 +1471,22 @@ module Squared
|
|
1481
1471
|
glob = kwargs.fetch(:include, [])
|
1482
1472
|
pass = kwargs.fetch(:exclude, [])
|
1483
1473
|
ret = {}
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1474
|
+
git_spawn('status -s --porcelain', *args, stdout: false)
|
1475
|
+
.first
|
1476
|
+
.each do |line|
|
1477
|
+
next unless (file = line[/^[A-Z ?!]{3}"?(.+?)"?$/, 1])
|
1478
|
+
next if !glob.empty? && glob.none? { |val| File.fnmatch?(val, file, File::FNM_DOTMATCH) }
|
1479
|
+
next if !pass.empty? && pass.any? { |val| File.fnmatch?(val, file, File::FNM_DOTMATCH) }
|
1480
|
+
|
1481
|
+
ret[file] = algorithm.hexdigest(File.read(basepath(file)))
|
1482
|
+
end
|
1492
1483
|
ret
|
1493
1484
|
end
|
1494
1485
|
|
1486
|
+
def git_spawn(*cmd, stdout: true)
|
1487
|
+
source(git_output(*cmd), io: true, banner: false, stdout: stdout)
|
1488
|
+
end
|
1489
|
+
|
1495
1490
|
def append_pull(opts, list, target: @session, no: nil, flag: nil, remote: nil)
|
1496
1491
|
cmd << '--force' if option('force')
|
1497
1492
|
rsm = append_submodules(target: target)
|
@@ -1540,14 +1535,14 @@ module Squared
|
|
1540
1535
|
end
|
1541
1536
|
end
|
1542
1537
|
|
1543
|
-
def append_pathspec(files = [], target: @session, expect: false, parent: false)
|
1538
|
+
def append_pathspec(files = [], target: @session, expect: false, parent: false, pass: true)
|
1544
1539
|
if session_arg?('pathspec-from-file')
|
1545
1540
|
option_clear files
|
1546
1541
|
else
|
1547
1542
|
if files.empty? && (val = option('pathspec'))
|
1548
1543
|
files = split_escape(val)
|
1549
1544
|
end
|
1550
|
-
files = projectmap(files, parent: parent)
|
1545
|
+
files = projectmap(files, parent: parent, pass: pass)
|
1551
1546
|
if !files.empty?
|
1552
1547
|
target << '--' << files.join(' ')
|
1553
1548
|
elsif expect
|
@@ -1588,13 +1583,11 @@ module Squared
|
|
1588
1583
|
|
1589
1584
|
def git_session(*cmd, opts: nil, worktree: true, **kwargs)
|
1590
1585
|
dir = worktree ? ["--work-tree=#{shell_quote(path)}", "--git-dir=#{shell_quote(gitpath)}"] : []
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
session('git', *dir, *cmd, **kwargs)
|
1597
|
-
end
|
1586
|
+
return session('git', *dir, *cmd, **kwargs) unless opts
|
1587
|
+
|
1588
|
+
opts = option_sanitize(opts, OPT_GIT[:common], target: dir).first
|
1589
|
+
ret = session('git', *dir, *cmd, **kwargs)
|
1590
|
+
[ret, opts]
|
1598
1591
|
end
|
1599
1592
|
|
1600
1593
|
def git_output(*cmd, **kwargs)
|
@@ -79,7 +79,7 @@ module Squared
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
subtasks({
|
83
83
|
'package' => %i[install dedupe update].freeze,
|
84
84
|
'outdated' => %i[major minor patch].freeze,
|
85
85
|
'bump' => %i[version major minor patch].freeze,
|
@@ -87,7 +87,7 @@ module Squared
|
|
87
87
|
'add' => nil,
|
88
88
|
'run' => nil,
|
89
89
|
'pack' => nil
|
90
|
-
}
|
90
|
+
})
|
91
91
|
|
92
92
|
def initialize(*, **kwargs)
|
93
93
|
super
|
@@ -145,8 +145,7 @@ module Squared
|
|
145
145
|
else
|
146
146
|
cmd = param_guard(action, 'command', args: args.to_a)
|
147
147
|
cmd.each do |val|
|
148
|
-
if (
|
149
|
-
n, opts = data
|
148
|
+
if (n, opts = indexitem(val))
|
150
149
|
if (item = list[n - 1])
|
151
150
|
val = opts ? "#{item.first} #{opts}" : item.first
|
152
151
|
elsif exception
|
@@ -593,42 +592,41 @@ module Squared
|
|
593
592
|
end).first
|
594
593
|
append_loglevel
|
595
594
|
option_clear out
|
595
|
+
run(from: :"package:#{flag}")
|
596
|
+
return
|
596
597
|
elsif pnpm?
|
597
598
|
cmd = session 'pnpm', flag
|
598
599
|
list = OPT_PNPM[:install_base] + OPT_PNPM.fetch(flag, []) + OPT_PNPM[:common]
|
599
600
|
list += OPT_PNPM[:install_as] unless flag == :dedupe
|
600
|
-
|
601
|
-
append_nocolor
|
602
|
-
append_loglevel
|
603
|
-
option_clear out
|
601
|
+
opts = option_sanitize(opts, list, no: OPT_PNPM[:"#{flag}_no"]).first
|
604
602
|
else
|
605
603
|
cmd = session 'npm', flag
|
606
604
|
list = OPT_NPM[:install_base] + OPT_NPM.fetch(flag, []) + OPT_NPM[:common]
|
607
605
|
list += OPT_NPM[:install_as] unless flag == :dedupe
|
608
606
|
opts, pat = option_sanitize(opts, list, no: OPT_NPM[:install_no])
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
elsif opt.include?('=')
|
618
|
-
err << opt
|
619
|
-
else
|
620
|
-
out << opt
|
607
|
+
end
|
608
|
+
out = []
|
609
|
+
err = []
|
610
|
+
opts.each do |opt|
|
611
|
+
if pat && opt =~ pat
|
612
|
+
case $1
|
613
|
+
when 'w', 'workspace'
|
614
|
+
cmd << (%r{[\\/]}.match?($2) ? quote_option($1, basepath($2)) : shell_option($1, $2))
|
621
615
|
end
|
622
|
-
|
623
|
-
|
624
|
-
append_loglevel
|
625
|
-
if flag == :dedupe
|
626
|
-
option_clear out
|
616
|
+
elsif opt.include?('=')
|
617
|
+
err << opt
|
627
618
|
else
|
628
|
-
|
619
|
+
out << opt
|
629
620
|
end
|
630
|
-
option_clear err
|
631
621
|
end
|
622
|
+
append_nocolor
|
623
|
+
append_loglevel
|
624
|
+
if flag == :dedupe
|
625
|
+
option_clear out
|
626
|
+
else
|
627
|
+
append_value(out, escape: true)
|
628
|
+
end
|
629
|
+
option_clear err
|
632
630
|
run(from: :"package:#{flag}")
|
633
631
|
end
|
634
632
|
|