squared 0.4.3 → 0.4.5

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.
@@ -6,8 +6,20 @@ module Squared
6
6
  class Ruby < Git
7
7
  GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
8
8
  DIR_RUBY = (GEMFILE + Rake::Application::DEFAULT_RAKEFILES + ['README.rdoc']).freeze
9
+ OPT_RUBY = {
10
+ rake: %w[A|all B|build-all comments n|dry-run p|execute-print=q m|multitask P|prereqs q|quiet
11
+ X|no-deprecation-warnings N|no-search G|no-system nosearch nosystem rules s|silent g|system
12
+ v|verbose backtrace=b? D|describe=q? e|execute=q E|execute-continue=q I|libdir=p job-stats=b?
13
+ j|jobs=i? R|rakelib=p rakelibdir=p r|require=b suppress-backtrace=q T|tasks=q? t|trace=b?
14
+ W|where=q?].freeze,
15
+ irb: %w[d f U w E=b I=p r=b W=m? autocomplete colorize echo echo-on-assignment extra-doc-dir inf-ruby-mode
16
+ inspect multiline no-pager noautocomplete nocolorize noecho noinspect noecho-on-assignment
17
+ nomultiline noprompt noscript nosingleline noverbose regexp-completor sample-book-mode script
18
+ simple-prompt single-irb singleline tracer truncate-echo-on-assignment type-completor verbose
19
+ back-trace-limit=i context-mode=i prompt=b prompt-mode=b].freeze
20
+ }.freeze
9
21
  OPT_BUNDLE = {
10
- common: %w[no-color V verbose retry=i].freeze,
22
+ common: %w[no-color V|verbose retry=i].freeze,
11
23
  install: %w[frozen no-cache no-prune system path=p binstubs=p? standalone=q? target-rbconfig=p trust-policy=b
12
24
  with=q without=q].freeze,
13
25
  install_base: %w[full-index quiet retry gemfile=p j|jobs=i].freeze,
@@ -15,6 +27,7 @@ module Squared
15
27
  outdated: %w[filter-major filter-minor filter-patch groups local parseable pre only-explicit strict
16
28
  update-strict g|group=q source=b].freeze,
17
29
  exec: %w[gemfile=p].freeze,
30
+ cache: %w[all-platforms frozen no-install no-prune quiet cache-path=p gemfile=p path=p].freeze,
18
31
  check: %w[dry-run gemfile=p].freeze
19
32
  }.freeze
20
33
  OPT_GEM = {
@@ -35,7 +48,7 @@ module Squared
35
48
  shared_no: %w[env-shebang force format-executable http-proxy lock minimal-deps post-install-message
36
49
  prerelease suggestions user-install wrappers].freeze
37
50
  }.freeze
38
- private_constant :GEMFILE, :DIR_RUBY, :OPT_BUNDLE, :OPT_GEM
51
+ private_constant :GEMFILE, :DIR_RUBY, :OPT_RUBY, :OPT_BUNDLE, :OPT_GEM
39
52
 
40
53
  class << self
41
54
  def populate(*); end
@@ -55,16 +68,18 @@ module Squared
55
68
  end
56
69
  end
57
70
 
58
- @@tasks[ref] = {
71
+ subtasks({
59
72
  'install' => %i[redownload local prefer-local].freeze,
60
73
  'update' => %i[patch minor major all].freeze,
61
74
  'outdated' => %i[patch minor major].freeze,
62
75
  'gem' => %i[install user-install update pristine outdated push build exec].freeze,
63
76
  'exec' => nil,
77
+ 'cache' => nil,
64
78
  'config' => nil,
65
79
  'check' => nil,
66
- 'rake' => nil
67
- }.freeze
80
+ 'rake' => nil,
81
+ 'irb' => nil
82
+ })
68
83
 
69
84
  def initialize(*, autodetect: false, **kwargs)
70
85
  super
@@ -109,24 +124,15 @@ module Squared
109
124
 
110
125
  if flags.nil?
111
126
  case action
112
- when 'config', 'exec', 'check'
113
- format_desc(action, nil, case action
114
- when 'exec', 'check'
115
- OPT_BUNDLE[action.to_sym]
116
- end, after: action == 'check' ? nil : 'command+')
117
- task action do |_, args|
118
- bundle action, args.to_a
119
- end
120
127
  when 'rake'
121
128
  next unless rakefile
122
129
 
123
- format_desc action, nil, 'command*|^index,args*|#,pattern*'
130
+ format_desc action, nil, 'tasks*,opts*|^index|#,pattern*'
124
131
  task action, [:command] do |_, args|
125
132
  if args.command == '#'
126
133
  format_list(read_rakefile, 'rake[^N]', 'tasks', grep: args.extras, from: rakefile.to_s,
127
134
  each: ->(val) { val[0] + val[1].to_s })
128
- elsif (data = indexitem(args.command))
129
- n, opts = data
135
+ elsif (n, opts = indexitem(args.command))
130
136
  list = read_rakefile
131
137
  if (item = list[n - 1])
132
138
  cmd = opts ? "#{opts} #{item.first}" : item.first
@@ -138,9 +144,27 @@ module Squared
138
144
  end
139
145
  rake(args.extras.empty? ? cmd : cmd + shell_escape("[#{args.extras.join(',')}]"))
140
146
  else
141
- rake(*args.to_a)
147
+ rake(opts: args.to_a)
142
148
  end
143
149
  end
150
+ when 'irb'
151
+ next unless (spec = basepath("#{project}.gemspec") || basepath("#{name}.gemspec"))
152
+ next unless basepath('lib').join("#{gemname = File.basename(spec, File.extname(spec))}.rb").exist?
153
+
154
+ format_desc action, nil, 'opts*,args*'
155
+ task action do |_, args|
156
+ irb gemname, args.to_a
157
+ end
158
+ else
159
+ format_desc(action, nil, OPT_BUNDLE[action.to_sym], after: case action
160
+ when 'cache', 'check'
161
+ nil
162
+ else
163
+ 'command+'
164
+ end)
165
+ task action do |_, args|
166
+ bundle(action, *args.to_a)
167
+ end
144
168
  end
145
169
  else
146
170
  namespace action do
@@ -342,7 +366,8 @@ module Squared
342
366
 
343
367
  def update(flag, opts = [])
344
368
  bundle_session 'update', "--#{flag}"
345
- append_bundle opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common]
369
+ append_bundle(opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common],
370
+ append: flag == :all ? nil : /^\w+=/)
346
371
  run_rb(from: :update)
347
372
  end
348
373
 
@@ -353,9 +378,9 @@ module Squared
353
378
  if (pwd = gempwd)
354
379
  cmd << pwd
355
380
  end
356
- cmd << flag
381
+ cmd << 'outdated'
357
382
  when :push
358
- cmd << flag << project
383
+ cmd << 'push' << project
359
384
  when :'user-install'
360
385
  cmd << 'install' << '--user-install'
361
386
  else
@@ -366,15 +391,21 @@ module Squared
366
391
  when :install, :'user-install', :update
367
392
  list += OPT_GEM[:shared]
368
393
  no = OPT_GEM[:shared_no]
394
+ first = true
395
+ when :pristine
396
+ first = true
369
397
  end
370
- opts, pat = option_sanitize(opts, list, no: no, first: true)
398
+ opts, pat = option_sanitize(opts, list, no: no, first: first)
371
399
  out = []
400
+ err = []
372
401
  opts.each do |opt|
373
402
  if opt =~ pat
374
403
  case $1
375
404
  when 'g', 'gem'
376
405
  cmd << (flag == :exec ? shell_option($1, $2) : quote_option($1, basepath($2)))
377
406
  end
407
+ elsif opt.match?(/^\w+=/) && !%i[outdated build push exec].include?(flag)
408
+ err << opt
378
409
  else
379
410
  out << opt
380
411
  end
@@ -383,6 +414,7 @@ module Squared
383
414
  case flag
384
415
  when :outdated
385
416
  log.info cmd.to_s
417
+ option_clear out
386
418
  on :first, from
387
419
  print_item format_banner(cmd.to_s)
388
420
  pwd_set(pass: !pwd.nil?, from: from) do
@@ -481,39 +513,59 @@ module Squared
481
513
  name = out.first
482
514
  if n == 0
483
515
  cmd << project
484
- version = name[1..-1]
516
+ ver = name[1..-1]
485
517
  else
486
518
  cmd << shell_escape(name[0, n])
487
- version = name[n + 1..-1]
519
+ ver = name[n + 1..-1]
488
520
  end
489
- cmd << shell_option('version', version)
521
+ cmd << shell_option('version', ver)
490
522
  out.clear
491
523
  end
492
524
  end
493
525
  append_value(out, escape: true)
526
+ option_clear err
494
527
  end
495
528
  run_rb(from: from)
496
529
  end
497
530
 
498
531
  def bundle(flag, *args)
499
- args = args.flatten
500
532
  cmd = bundle_session flag
533
+ args = case flag
534
+ when 'exec', 'cache', 'check'
535
+ option_sanitize(args, OPT_BUNDLE[flag.to_sym] + OPT_BUNDLE[:common], args: flag == :exec).first
536
+ else
537
+ args.flatten
538
+ end
501
539
  case flag
502
- when 'exec', 'check'
503
- args = option_sanitize(args, OPT_BUNDLE[flag.to_sym] + OPT_BUNDLE[:common]).first
540
+ when 'exec', 'config'
541
+ raise_error('no command given', hint: flag) if args.empty?
542
+ cmd.merge(args)
543
+ else
544
+ option_clear args
504
545
  end
505
- raise_error('no command given', hint: flag) unless !args.empty? || flag == 'check'
506
- cmd.merge(args)
507
546
  run(from: :"bundle:#{flag}")
508
547
  end
509
548
 
510
- def rake(*cmd)
511
- if cmd.empty?
512
- run_s(rake_output(rakeapp), from: :rake, chdir: workspace.pwd)
549
+ def rake(*args, opts: [])
550
+ target = [quote_option('f', rakefile)]
551
+ args += option_sanitize(opts, OPT_RUBY[:rake], target: target).first
552
+ if args.empty?
553
+ args << nil
513
554
  else
514
- cmd = cmd.flatten.map { |val| rake_output(rakeapp, val) }
515
- run_s(cmd, from: :rake, chdir: workspace.pwd, banner: false)
555
+ args.flatten!
516
556
  end
557
+ cmd = rake_output(*target)
558
+ args.map! { |val| cmd.temp(val) }
559
+ run_s(args, banner: false, from: :rake)
560
+ end
561
+
562
+ def irb(name, opts = [], path: basepath('lib'))
563
+ cmd = session 'irb'
564
+ args = option_sanitize(opts, OPT_RUBY[:irb], first: true).first
565
+ as_a(name).each { |val| cmd << shell_option('r', val) }
566
+ as_a(path).each { |val| cmd << quote_option('I', val) }
567
+ cmd.merge(args)
568
+ run(banner: false)
517
569
  end
518
570
 
519
571
  def depend?
@@ -586,9 +638,17 @@ module Squared
586
638
  run(banner: !@session.include?('--quiet'), **kwargs)
587
639
  end
588
640
 
589
- def append_bundle(opts, list, target: @session)
641
+ def append_bundle(opts, list, target: @session, append: nil)
590
642
  out = option_sanitize(opts, list, target: target).first
591
- option_clear(out, target: target)
643
+ if append
644
+ if append.is_a?(Regexp)
645
+ out, err = out.partition { |val| !val.match?(append) }
646
+ option_clear(err, target: target)
647
+ end
648
+ append_value(out, target: target, escape: true)
649
+ else
650
+ option_clear(out, target: target)
651
+ end
592
652
  end
593
653
 
594
654
  def gem_session(*cmd, **kwargs)
@@ -648,10 +708,6 @@ module Squared
648
708
  basepath file
649
709
  end
650
710
 
651
- def rakeapp
652
- quote_option 'rakefile', Rake.application.rakefile
653
- end
654
-
655
711
  def rakepwd
656
712
  return unless Rake::VERSION >= '13.0.4'
657
713
 
@@ -179,7 +179,7 @@ module Squared
179
179
  parse_opts.(args)
180
180
  stage = 'init'
181
181
  puts if newline
182
- system("repo init -u #{manifest_url} -m #{args.manifest || target}.xml", chdir: root)
182
+ system("repo init -u #{env('REPO_URL') || manifest_url} -m #{args.manifest || target}.xml", chdir: root)
183
183
  repo['all'].invoke
184
184
  end
185
185
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubygems_version: 3.6.2
124
+ rubygems_version: 3.6.7
125
125
  specification_version: 4
126
126
  summary: Rake task generator for managing multi-language workspaces.
127
127
  test_files: []