squared 0.1.1 → 0.1.3

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.
@@ -4,8 +4,8 @@ module Squared
4
4
  module Workspace
5
5
  module Project
6
6
  class Git < Base
7
- OPT_PULL = %w[all ff-only autostash prune tags depth=n since=d jobs=n dry-run].freeze
8
- OPT_FETCH = %w[prune-tags].concat(OPT_PULL[3..-1]).freeze
7
+ OPT_FETCH = %w[all tags prune append atomic unshallow dry-run depth=i deepen=i since=d jobs=i].freeze
8
+ OPT_PULL = %w[ff ff-only edit autostash squash verify <fetch].freeze
9
9
  private_constant :OPT_PULL, :OPT_FETCH
10
10
 
11
11
  class << self
@@ -17,7 +17,7 @@ module Squared
17
17
  namespace(name = ws.task_name('git')) do
18
18
  all = ws.task_join(name, 'all')
19
19
 
20
- desc ws.task_name("#{all}[git?=rebase|stash,depend?]", desc: true)
20
+ desc Common::Format.message(*"#{all}[git?=rebase|stash,depend?]".split(':'))
21
21
  task 'all', [:git, :depend] do |_, args|
22
22
  cmd = case args.git
23
23
  when 'rebase'
@@ -63,7 +63,8 @@ module Squared
63
63
  reset: %i[head soft mixed hard merge keep submodules].freeze,
64
64
  restore: %i[worktree staged overlay].freeze,
65
65
  rev: %i[commit branch].freeze,
66
- show: %i[oneline pretty format].freeze
66
+ show: %i[oneline pretty format].freeze,
67
+ tag: %i[add delete list merged].freeze
67
68
  }.freeze
68
69
 
69
70
  def initialize(*, **)
@@ -85,7 +86,7 @@ module Squared
85
86
  flags.each do |flag|
86
87
  case action
87
88
  when :pull, :fetch
88
- desc format_desc(action, flag, flag == :pull ? OPT_PULL : OPT_FETCH)
89
+ desc format_desc(action, flag, action == :pull ? OPT_PULL : OPT_FETCH)
89
90
  task flag, [:opts] do |_, args|
90
91
  __send__(action, flag, opts: args.to_a)
91
92
  end
@@ -102,6 +103,32 @@ module Squared
102
103
  __send__(action, flag, files)
103
104
  end
104
105
  end
106
+ when :tag
107
+ case flag
108
+ when :list
109
+ desc format_desc(action, flag, 'pattern*')
110
+ task flag, [:pattern] do |_, args|
111
+ tag(flag, args.to_a)
112
+ end
113
+ when :merged
114
+ desc format_desc(action, flag, 'commit,pattern*')
115
+ task flag, [:commit, :pattern] do |_, args|
116
+ commit = guard_params(action, flag, args: args, key: :commit)
117
+ tag(flag, args.to_a.drop(1), commit: commit)
118
+ end
119
+ when :delete
120
+ desc format_desc(action, flag, 'name+')
121
+ task flag, [:name] do |_, args|
122
+ name = guard_params(action, flag, args: args.to_a)
123
+ tag(flag, name)
124
+ end
125
+ else
126
+ desc format_desc(action, flag, 'name,message?,commit?')
127
+ task flag, [:name, :message, :commit] do |_, args|
128
+ name = guard_params(action, flag, args: args, key: :name)
129
+ tag(flag, [name], message: args.message, commit: args.commit)
130
+ end
131
+ end
105
132
  when :stash
106
133
  if flag == :push
107
134
  desc format_desc(action, flag, 'pathspec*')
@@ -130,7 +157,7 @@ module Squared
130
157
  desc format_desc(action, flag, 'index?=0,pathspec*')
131
158
  task flag, [:pathspec] do |_, args|
132
159
  files = args.to_a
133
- diff(flag, files, index: /^\d+$/.match?(files[0]) && !option('index') ? files.shift.to_i : 0)
160
+ diff(flag, files, index: /\A\d+\z/.match?(files[0]) && !option('index') ? files.shift.to_i : 0)
134
161
  end
135
162
  when :cached
136
163
  desc format_desc(action, flag, 'pathspec*')
@@ -139,9 +166,9 @@ module Squared
139
166
  end
140
167
  when :branch
141
168
  desc format_desc(action, flag, 'name,pathspec*')
142
- task flag, [:name, :pathspec] do |_, args|
169
+ task flag, [:name] do |_, args|
143
170
  branch = guard_params(action, flag, args: args, key: :name)
144
- diff(flag, args.to_a[1..-1] || [], branch: branch)
171
+ diff(flag, args.to_a.drop(1), branch: branch)
145
172
  end
146
173
  when :files
147
174
  desc format_desc(action, flag, 'path1,path2')
@@ -173,7 +200,7 @@ module Squared
173
200
  detach = args.detach
174
201
  commit = args.commit
175
202
  end
176
- guard_params(action, flag, args: { create: create }, key: :create, pat: /^b$/i) if create
203
+ guard_params(action, flag, args: { create: create }, key: :create, pat: /\Ab\z/i) if create
177
204
  checkout(flag, branch: branch, create: create, commit: commit, detach: detach)
178
205
  end
179
206
  when :detach
@@ -191,7 +218,7 @@ module Squared
191
218
  if flag == :head
192
219
  desc format_desc(action, flag, 'ref,pathspec+')
193
220
  task flag, [:ref, :pathspec] do |_, args|
194
- files = guard_params(action, flag, args: args.to_a[1..-1] || [])
221
+ files = guard_params(action, flag, args: args.to_a.drop(1))
195
222
  reset(flag, files, ref: args.ref)
196
223
  end
197
224
  else
@@ -204,15 +231,12 @@ module Squared
204
231
  if flag == :oneline
205
232
  desc format_desc(action, flag, 'object*')
206
233
  task flag, [:object] do |_, args|
207
- objs = args.to_a
208
- show(objs, pretty: 'oneline', abbrev: true)
234
+ show(args.to_a, pretty: 'oneline', abbrev: true)
209
235
  end
210
236
  else
211
237
  desc format_desc(action, flag, 'format,object*')
212
238
  task flag, [:format, :object] do |_, args|
213
- format = guard_params(action, flag, args: args, key: :format)
214
- objs = args.to_a[1..-1] || []
215
- show(objs, "#{flag}": format)
239
+ show(args.to_a.drop(1), "#{flag}": args.format)
216
240
  end
217
241
  end
218
242
  end
@@ -272,16 +296,16 @@ module Squared
272
296
  def status
273
297
  cmd = git_session 'status', option('long') ? '--long' : '--short'
274
298
  if (val = option('ignore-submodules', ignore: false))
275
- cmd << "--ignore-submodules=#{case val
276
- when '0', 'none'
277
- 'none'
278
- when '1', 'untracked'
279
- 'untracked'
280
- when '2', 'dirty'
281
- 'dirty'
282
- else
283
- 'all'
284
- end}"
299
+ cmd << shell_option('ignore-submodules', case val
300
+ when '0', 'none'
301
+ 'none'
302
+ when '1', 'untracked'
303
+ 'untracked'
304
+ when '2', 'dirty'
305
+ 'dirty'
306
+ else
307
+ 'all'
308
+ end, escape: false)
285
309
  end
286
310
  append_pathspec
287
311
  out, banner = source(io: true)
@@ -339,18 +363,39 @@ module Squared
339
363
  cmd << "--#{flag}" << commit
340
364
  else
341
365
  cmd << "--#{flag}"
342
- append_ours
366
+ append_first %w[ours theirs]
343
367
  append_head
344
368
  append_pathspec files
345
369
  end
346
370
  source
347
371
  end
348
372
 
373
+ def tag(flag, refs, message: nil, commit: nil)
374
+ cmd = git_session 'tag'
375
+ case flag
376
+ when :add
377
+ if option('sign')
378
+ cmd << '--sign'
379
+ else
380
+ out = cmd.to_s
381
+ cmd << '--annotate' if %w[-s --sign -u --local-user].none? { |val| out.include?(" #{val}") }
382
+ end
383
+ append_message message
384
+ append_value(refs, escape: false)
385
+ append_head commit
386
+ when :delete, :list, :merged
387
+ cmd << shell_option(flag, commit)
388
+ append_option(%w[contains sort] + (flag == :list ? ['merged'] : []), equals: true) unless flag == :delete
389
+ append_value(refs, escape: false)
390
+ end
391
+ source
392
+ end
393
+
349
394
  def rev(flag, ref: nil, size: nil)
350
395
  git_session 'rev-parse', if flag == :branch
351
396
  '--abbrev-ref'
352
397
  else
353
- (n = size.to_i) > 0 ? "--short=#{[n, 5].max}" : '--verify'
398
+ (n = size.to_i) > 0 ? shell_option('short', [n, 5].max, escape: false) : '--verify'
354
399
  end
355
400
  append_commit ref
356
401
  source
@@ -375,7 +420,7 @@ module Squared
375
420
  def diff(flag, files = [], branch: nil, index: 0)
376
421
  cmd = git_session 'diff'
377
422
  unless flag == :files
378
- if /^#[0-9a-f]{5,40}\#$/.match?(sha = files.first)
423
+ if /\A#\h{5,40}\#\z/.match?(sha = files.first)
379
424
  sha = sha[1..-2]
380
425
  files.shift
381
426
  else
@@ -383,7 +428,7 @@ module Squared
383
428
  end
384
429
  end
385
430
  if (val = option('unified')).to_i > 0
386
- cmd << "--unified=#{val}"
431
+ cmd << shell_option('unified', val, escape: false)
387
432
  end
388
433
  append_nocolor
389
434
  case flag
@@ -425,14 +470,14 @@ module Squared
425
470
  upstream = false
426
471
  source('git fetch --no-tags --quiet', io: true, banner: false)
427
472
  source('git branch -vv --list', io: true, banner: false).first.each do |val|
428
- next unless (data = /^\*\s(\S+)\s+(\h+)(?:\s\[(.+?)(?=\]\s)\])?\s/.match(val))
473
+ next unless (data = /\A\*\s(\S+)\s+(\h+)(?:\s\[(.+?)(?=\]\s)\])?\s/.match(val))
429
474
 
430
475
  branch = data[1]
431
476
  sha = data[2]
432
477
  if !data[3]
433
478
  unless (origin = option('repository', prefix: 'git', ignore: false))
434
479
  out = source('git log -n1 --format=%h%d', io: true, stdout: true, banner: false).first
435
- if (data = /^#{sha} \(HEAD -> #{Regexp.escape(branch)}, (.+?)\)$/m.match(out))
480
+ if (data = /\A#{sha} \(HEAD -> #{Regexp.escape(branch)}, (.+?)\)\z/.match(out))
436
481
  split_escape(data[1]).each do |val|
437
482
  next unless val.end_with?("/#{branch}")
438
483
 
@@ -442,7 +487,7 @@ module Squared
442
487
  end
443
488
  end
444
489
  upstream = !origin.nil?
445
- elsif (data = Regexp.new("^(.+)/#{Regexp.escape(branch)}$").match(data[3]))
490
+ elsif (data = Regexp.new("\\A(.+)/#{Regexp.escape(branch)}\\z").match(data[3]))
446
491
  origin = data[1]
447
492
  end
448
493
  break
@@ -469,7 +514,7 @@ module Squared
469
514
  end
470
515
  a << pathspec
471
516
  b << '--force' if amend
472
- b << @origin << @branch
517
+ b << origin << branch
473
518
  puts if pass
474
519
  source a.join(' ')
475
520
  source cmd
@@ -478,27 +523,25 @@ module Squared
478
523
 
479
524
  def restore(flag, files)
480
525
  git_session 'restore', "--#{flag}"
481
- append_ours
526
+ append_first %w[ours theirs]
482
527
  append_pathspec(files, expect: true)
483
528
  source(stdout: true)
484
529
  end
485
530
 
486
531
  def show(objs, pretty: nil, format: nil, abbrev: nil)
487
532
  cmd = git_session 'show'
488
- case (flag = pretty&.downcase)
489
- when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
490
- cmd << "--pretty=#{flag}"
491
- else
492
- if pretty
493
- cmd << "--pretty=#{shell_escape("tformat:#{pretty}", quote: true)}"
494
- elsif format
495
- cmd << "--format=#{shell_escape(format, quote: true)}"
496
- end
533
+ if (flag = pretty || format)
534
+ cmd << case (val = flag.downcase)
535
+ when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
536
+ shell_option('format', val, escape: false)
537
+ else
538
+ shell_option('pretty', flag, escape: false, quote: true)
539
+ end
497
540
  end
498
541
  if (abbrev ||= option('abbrev')) == true
499
542
  cmd << '--abbrev-commit'
500
543
  elsif abbrev.to_i > 0
501
- cmd << "--abbrev=#{abbrev}"
544
+ cmd << shell_option('abbrev', abbrev, escape: false)
502
545
  end
503
546
  append_value objs
504
547
  source(exception: false)
@@ -511,7 +554,7 @@ module Squared
511
554
  cmd = session_done(cmd)
512
555
  log.info cmd
513
556
  banner = format_banner(cmd.gsub(File.join(path, ''), ''), banner: banner)
514
- cmd = cmd.sub(/^git\b/, "git --work-tree=#{shell_quote(path)} --git-dir=#{shell_quote(gitpath)}")
557
+ cmd = cmd.sub(/\Agit\b/, "git --work-tree=#{shell_quote(path)} --git-dir=#{shell_quote(gitpath)}")
515
558
  begin
516
559
  if io
517
560
  [stdout ? `#{cmd}` : IO.popen(cmd), banner]
@@ -580,8 +623,8 @@ module Squared
580
623
  if size > 0
581
624
  styles = theme.fetch(:banner, []).reject { |s| s.to_s.end_with?('!') }
582
625
  styles << :bold if styles.size <= 1
583
- puts print_footer("#{size} #{size == 1 ? type.sub(/s$/, '') : type}",
584
- sub: { styles: styles, pat: /^(\d+)(.+)$/ })
626
+ puts print_footer("#{size} #{size == 1 ? type.sub(/s\z/, '') : type}",
627
+ sub: { pat: /\A(\d+)(.+)\z/, styles: styles })
585
628
  else
586
629
  puts empty_status("No #{type} were #{action}", 'grep', grep)
587
630
  end
@@ -589,11 +632,14 @@ module Squared
589
632
 
590
633
  def append_pull(opts, list, flag = nil)
591
634
  append_submodules flag
635
+ list = list.grep_v(/[^a-z\-]/)
592
636
  opts.each do |opt|
593
- if list.include?(opt) || opt.match(/^(?:depth|jobs)=\d+$/)
637
+ if list.include?(opt) || opt.match(/^(?:de(?:pth|epen)|jobs)=\d+$/)
594
638
  @session << "--#{opt}"
595
- elsif opt.match(/^since=(.+)$/) && (val = Date.parse($1))
596
- @session << "--shallow-since=\"#{val.strftime('%F %T')}\""
639
+ elsif opt.match(/^(?:shallow-)?since=(.+)$/) && (val = Date.parse($1))
640
+ @session << shell_option('shallow-since', val.strftime('%F %T'), escape: false, quote: true)
641
+ elsif opt.end_with?('!') && list.include?(opt = opt[0..-2])
642
+ @session << "--no-#{opt}"
597
643
  end
598
644
  end
599
645
  end
@@ -616,19 +662,13 @@ module Squared
616
662
  end
617
663
 
618
664
  def append_message(val)
619
- @session << "--message=\"#{double_quote(val)}\"" if val
665
+ @session << "--message=\"#{double_quote(val)}\"" unless val.to_s.empty?
620
666
  end
621
667
 
622
- def append_head
623
- @session << (option('head') || option('tree-ish'))
624
- end
668
+ def append_head(val = nil)
669
+ return @session << val if val
625
670
 
626
- def append_ours
627
- if option('ours')
628
- @session << '--ours'
629
- elsif option('theirs')
630
- @session << '--theirs'
631
- end
671
+ append_first(%w[head tree-ish object], flag: false, ignore: false)
632
672
  end
633
673
 
634
674
  def append_submodules(flag = nil)
@@ -12,11 +12,11 @@ module Squared
12
12
  end
13
13
 
14
14
  def batchargs
15
- [ref, { refresh: %i[build copy] }]
15
+ [ref, { refresh: %i[build copy] }].freeze
16
16
  end
17
17
 
18
18
  def aliasargs
19
- [ref, { refresh: :build }]
19
+ [ref, { refresh: :build }].freeze
20
20
  end
21
21
 
22
22
  def bannerargs
@@ -103,7 +103,7 @@ module Squared
103
103
  when :install
104
104
  desc format_desc(action, flag)
105
105
  task flag do
106
- depend(flag)
106
+ depend flag
107
107
  end
108
108
  when :outdated
109
109
  desc format_desc(action, flag, %w[prune interactive dry-run].freeze, arg: 'opts?')
@@ -144,7 +144,7 @@ module Squared
144
144
  items += as_a(also) if also
145
145
  return if items.empty?
146
146
 
147
- print_item unless @output[0] || !verbose || task_invoked?(/^copy(?::#{Node.ref}|$)/)
147
+ print_item unless @output[0] || !verbose || task_invoked?(/\Acopy(?::#{Node.ref}|$)/)
148
148
  items.each do |dir|
149
149
  case dir
150
150
  when Pathname
@@ -243,7 +243,7 @@ module Squared
243
243
  end
244
244
  cmd << '--prod' if flag && prod?
245
245
  if (val = option('public-hoist-pattern', ignore: false))
246
- split_escape(val).each { |opt| cmd << "--public-hoist-pattern=#{shell_escape(opt, quote: true)}" }
246
+ split_escape(val).each { |opt| cmd << shell_option('public-hoist-pattern', opt, quote: true) }
247
247
  end
248
248
  cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0')
249
249
  append_nocolor option('no-color')
@@ -279,10 +279,7 @@ module Squared
279
279
  end
280
280
  log.info cmd
281
281
  banner = format_banner("#{cmd}#{dryrun ? ' --dry-run' : ''}")
282
- if sync
283
- print_item banner
284
- banner = nil
285
- end
282
+ print_item banner if sync
286
283
  begin
287
284
  data = pwd_set { `#{cmd} --json --loglevel=error` }
288
285
  json = JSON.parse(doc = dependfile.read)
@@ -316,8 +313,9 @@ module Squared
316
313
  avail << [key, file, latest, true]
317
314
  next
318
315
  end
316
+ current = val['current'] || file
319
317
  want = rev == :major && (ver = latest.match(SEM_VER)) && !ver[6] ? latest : val['wanted']
320
- next unless (val['current'] != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
318
+ next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
321
319
 
322
320
  f = semscan(file)
323
321
  w = semscan(want)
@@ -345,7 +343,7 @@ module Squared
345
343
  end
346
344
  found << [key, file, want, index, major, f, w]
347
345
  elsif !major
348
- avail << [key, file, latest, false]
346
+ avail << [key, file, latest, latest != current]
349
347
  end
350
348
  end
351
349
  end
@@ -366,7 +364,7 @@ module Squared
366
364
  end
367
365
  puts print_footer(empty_status(msg, hint, pending + val))
368
366
  end
369
- print_item banner if banner
367
+ print_item banner unless sync
370
368
  if !found.empty?
371
369
  col1 = size_col.(found, 0) + 4
372
370
  col2 = size_col.(found, 1) + 4
@@ -465,8 +463,8 @@ module Squared
465
463
  major = flag == :major
466
464
  emphasize("version: #{out}", title: name, border: borderstyle, sub: [
467
465
  headerstyle,
468
- { pat: /^(version:)( )(\S+)(.*)$/, styles: color(major ? :green : :yellow), index: 3 },
469
- { pat: /^(version:)(.*)$/, styles: theme[major ? :major : :active] }
466
+ { pat: /\A(version:)( )(\S+)(.*)\z/, styles: color(major ? :green : :yellow), index: 3 },
467
+ { pat: /\A(version:)(.*)\z/, styles: theme[major ? :major : :active] }
470
468
  ])
471
469
  elsif stdin?
472
470
  puts out
@@ -510,7 +508,7 @@ module Squared
510
508
  append_loglevel
511
509
  case opts
512
510
  when Enumerable
513
- ret += opts.to_a
511
+ ret.merge(opts.to_a)
514
512
  when String
515
513
  ret << opts
516
514
  else
@@ -653,19 +651,19 @@ module Squared
653
651
  end
654
652
  elsif pnpm?
655
653
  if silent
656
- @session << '--reporter=silent'
654
+ @session << shell_option('reporter', 'silent', escape: false)
657
655
  level ||= 'error'
658
656
  end
659
657
  case level
660
658
  when 'debug', 'info', 'warn', 'error'
661
- @session << "--loglevel=#{level}"
659
+ @session << shell_option('loglevel', level, escape: false)
662
660
  end
663
661
  elsif silent
664
- @session << '--loglevel=silent'
662
+ @session << shell_option('loglevel', 'silent', escape: false)
665
663
  else
666
664
  case level
667
665
  when 'error', 'warn', 'notice', 'http', 'info', 'verbose', 'silly'
668
- @session << "--loglevel=#{level}"
666
+ @session << shell_option('loglevel', level, escape: false)
669
667
  end
670
668
  end
671
669
  end
@@ -80,7 +80,7 @@ module Squared
80
80
  if flag == :target
81
81
  task flag, [:dir, :opts] do |_, args|
82
82
  dir = guard_params(action, flag, args: args, key: :dir)
83
- depend(flag, dir: dir, opts: args.to_a[1..-1] || [])
83
+ depend(flag, dir: dir, opts: args.to_a.drop(1))
84
84
  end
85
85
  else
86
86
  task flag do |_, args|
@@ -106,7 +106,7 @@ module Squared
106
106
  cmd << '--user'
107
107
  append_pip opts, OPT_USER
108
108
  when :target
109
- cmd << "--target=#{shell_escape(basepath(dir), quote: true)}"
109
+ cmd << shell_option('target', basepath(dir), quote: true)
110
110
  append_pip opts, OPT_USER + ['upgrade']
111
111
  append_eager opts
112
112
  when :upgrade
@@ -122,7 +122,7 @@ module Squared
122
122
  cmd << (type == 1 ? '-r requirements.txt' : '.')
123
123
  run(sync: sync)
124
124
  when 3
125
- run_s("#{@bin} setup.py install", sync: sync)
125
+ run_s('python setup.py install', sync: sync)
126
126
  end
127
127
  end
128
128
  end
@@ -164,21 +164,21 @@ module Squared
164
164
 
165
165
  def append_pip(opts = [], list = [])
166
166
  opts.each do |opt|
167
- next unless list.include?(opt) || OPT_GENERAL.include?(opt) || (v = opt.match(/^v+$/))
167
+ data = nil
168
+ next unless list.include?(opt) || OPT_GENERAL.include?(opt) || (data = opt.match(/^verbose|(v+)$/))
168
169
 
169
170
  @session << case opt
170
171
  when 'venv'
171
172
  '--require-virtualenv'
172
173
  else
173
- (v ? "-#{v[0]}" : "--#{opt}")
174
+ (data && data[1] ? "-#{data[1]}" : "--#{opt}")
174
175
  end
175
176
  end
176
- if (val = option('proxy', ignore: false))
177
- @session << "--proxy=#{shell_escape(val, quote: true)}"
178
- end
179
- @session << "--python=#{shell_escape(basepath(val), quote: true)}" if (val = option('python', ignore: false))
180
- @session << "--log=#{shell_escape(basepath(val), quote: true)}" if (val = option('log', ignore: false))
181
- @session << '--user' if option('user')
177
+ val = nil
178
+ @session << shell_option('proxy', val, quote: true) if (val = option('proxy'))
179
+ @session << shell_option('python', basepath(val), quote: true) if (val = option('python'))
180
+ @session << shell_option('log', basepath(val), quote: true) if (val = option('log', ignore: false))
181
+ @session << '--user' if !list.empty? && option('user')
182
182
  @session << '--no-input' if option('no-input')
183
183
  append_nocolor option('no-color')
184
184
  end