squared 0.4.12 → 0.4.14

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.
@@ -81,7 +81,7 @@ module Squared
81
81
  'install' => %i[redownload local prefer-local].freeze,
82
82
  'update' => %i[patch minor major all].freeze,
83
83
  'outdated' => %i[patch minor major].freeze,
84
- 'gem' => %i[install uninstall update pristine outdated push build exec].freeze,
84
+ 'gem' => %i[install uninstall update pristine outdated build push exec].freeze,
85
85
  'ruby' => %i[file script version].freeze,
86
86
  'exec' => nil,
87
87
  'cache' => nil,
@@ -100,13 +100,12 @@ module Squared
100
100
  initialize_build(Ruby.ref, **kwargs)
101
101
  initialize_env(**kwargs)
102
102
  end
103
+ dependfile_set GEMFILE
103
104
  @autodetect = autodetect
104
- @dependindex = GEMFILE.index { |file| basepath(file).exist? }
105
- @dependfile = @path + GEMFILE[@dependindex || 0]
106
- return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || (file = rakefile).nil?
105
+ return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || rakefile.empty?
107
106
 
108
107
  begin
109
- File.foreach(file) do |line|
108
+ File.foreach(rakefile) do |line|
110
109
  next unless line.match?(%r{\brequire\s+(["'])bundler/gem_tasks\1})
111
110
 
112
111
  cmd = bundle_output('exec rake').to_s
@@ -135,26 +134,36 @@ module Squared
135
134
  if flags.nil?
136
135
  case action
137
136
  when 'rake'
138
- next unless rakefile
137
+ next if rakefile.empty?
139
138
 
140
- format_desc action, nil, 'tasks*,opts*|^index|#,pattern*'
139
+ format_desc action, nil, "task+,opts*|#{indexchar}index+|#,pattern*"
141
140
  task action, [:command] do |_, args|
142
141
  if args.command == '#'
143
- format_list(read_rakefile, 'rake[^N]', 'tasks', grep: args.extras, from: rakefile.to_s,
144
- each: ->(val) { val[0] + val[1].to_s })
145
- elsif (n, opts = indexitem(args.command))
146
- list = read_rakefile
147
- if (item = list[n - 1])
148
- cmd = opts ? "#{opts} #{item.first}" : item.first
149
- elsif exception
150
- indexerror n, list
142
+ format_list(read_rakefile, "rake[#{indexchar}N]", 'tasks', grep: args.extras, from: rakefile,
143
+ each: ->(val) { val[0] + val[1].to_s })
144
+ else
145
+ args, opts = args.to_a.partition { |val| indexitem(val) }
146
+ if args.empty?
147
+ rake(opts: opts)
151
148
  else
152
- log.warn "rake task #{n} of #{list.size} (out of range)"
153
- next
149
+ list = read_rakefile
150
+ while (n, pre = indexitem(args.shift))
151
+ if (item = list[n - 1])
152
+ cmd = pre ? "#{pre} #{item.first}" : item.first
153
+ elsif exception
154
+ indexerror n, list
155
+ else
156
+ log.warn "rake task #{n} of #{list.size} (out of range)"
157
+ next
158
+ end
159
+ if opts.empty?
160
+ rake cmd
161
+ else
162
+ rake(cmd + shell_escape("[#{opts.join(',')}]"))
163
+ opts.clear
164
+ end
165
+ end
154
166
  end
155
- rake(args.extras.empty? ? cmd : cmd + shell_escape("[#{args.extras.join(',')}]"))
156
- else
157
- rake(opts: args.to_a)
158
167
  end
159
168
  end
160
169
  when 'irb'
@@ -164,16 +173,12 @@ module Squared
164
173
  format_desc action, nil, 'opts*,args*|:'
165
174
  task action do |_, args|
166
175
  args = args.to_a
167
- if args.last == ':'
168
- args.pop
169
- load = readline('Enter file and arguments', force: false)
170
- end
171
- irb(gemname, args, load: load)
176
+ irb(gemname, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
172
177
  end
173
178
  else
174
- format_desc(action, nil, OPT_BUNDLE[action.to_sym], after: case action
175
- when 'cache', 'check' then nil
176
- else 'command+' end)
179
+ format_desc(action, nil, 'opts*', before: case action
180
+ when 'cache', 'check' then nil
181
+ else 'command+' end)
177
182
  task action do |_, args|
178
183
  bundle(action, *args.to_a)
179
184
  end
@@ -195,20 +200,24 @@ module Squared
195
200
  case (filter = args.semver)
196
201
  when 'major', 'minor', 'patch', 'interactive', 'i'
197
202
  filter = 'interactive' if filter == 'i'
198
- args = args.to_a.drop(1)
203
+ args = args.extras
199
204
  else
200
205
  filter = nil
201
206
  args = args.to_a
202
207
  end
203
208
  gem!(flag, args, filter: filter)
204
209
  end
205
- when :build, :push, :exec
206
- format_desc(action, flag, 'opts*', before: flag == :exec ? 'command+' : nil)
210
+ when :build, :push, :exec, :update
211
+ format_desc(action, flag, 'opts*', after: case flag
212
+ when :exec then 'command,args*'
213
+ when :push then 'file?'
214
+ when :update then 'name*'
215
+ end)
207
216
  task flag do |_, args|
208
217
  gem! flag, args.to_a
209
218
  end
210
219
  else
211
- format_desc action, flag, "opts*,name+#{flag == :pristine ? '|name?@version' : ''}"
220
+ format_desc(action, flag, 'opts*', after: flag == :pristine ? 'name*|name?@version' : 'name*')
212
221
  task flag do |_, args|
213
222
  args = param_guard(action, flag, args: args.to_a)
214
223
  gem! flag, args
@@ -219,15 +228,19 @@ module Squared
219
228
  when :file
220
229
  format_desc action, flag, 'path,opts*,args*'
221
230
  task flag, [:rb] do |_, args|
222
- if (file = args.rb)
223
- args = args.to_a.drop(1)
224
- else
225
- file, opts, extra = choice_index('Select a file', Dir.glob('*.rb', base: path),
226
- values: %w[Options Arguments], force: true, series: true)
227
- args = OptionPartition.strip(opts)
228
- ENV['RUBY_ARGS'] = extra if extra
231
+ file = args.rb
232
+ args = args.extras
233
+ unless file && !file.include?('*')
234
+ file, opts, prog = choice_index('Select a file', Dir.glob(file || (path + '*.rb')),
235
+ values: (file ? [] : ['Options']) << 'Arguments',
236
+ force: true, series: !args.include?('v'))
237
+ if file
238
+ prog = opts
239
+ else
240
+ args.concat(OptionPartition.strip(opts))
241
+ end
229
242
  end
230
- ruby(flag, args, file: file)
243
+ ruby(flag, args, file: file, args: prog)
231
244
  end
232
245
  when :script
233
246
  format_desc action, flag, 'opts*,args*'
@@ -281,8 +294,8 @@ module Squared
281
294
  on :first, :copy
282
295
  dest = Pathname.new(into).realpath
283
296
  print_item unless @output[0] || task_invoked?(/^copy(?::#{Ruby.ref}|$)/)
284
- glob = as_a(glob || '**/*')
285
- as_a(from).each_with_index do |val, i|
297
+ glob = Array(glob || '**/*')
298
+ Array(from).each_with_index do |val, i|
286
299
  a = path + val
287
300
  b = dest + val
288
301
  c = glob[i] || glob.first
@@ -427,7 +440,7 @@ module Squared
427
440
  run_rb(from: :update)
428
441
  end
429
442
 
430
- def ruby(flag, opts = [], file: nil, command: nil)
443
+ def ruby(flag, opts = [], file: nil, command: nil, args: nil)
431
444
  case flag
432
445
  when :file, :script
433
446
  op = OptionPartition.new(opts, OPT_RUBY[:ruby], ruby_session, project: self, args: true)
@@ -436,9 +449,7 @@ module Squared
436
449
  elsif command
437
450
  op << quote_option('e', command, option: false)
438
451
  end
439
- if (args = ENV['RUBY_ARGS'])
440
- op.extras << args
441
- end
452
+ op.extras << args if (args = ENV.fetch('RUBY_ARGS', args))
442
453
  op.append(delim: true, escape: false, quote: false) unless op.empty?
443
454
  when :version
444
455
  pwd_set do
@@ -473,6 +484,8 @@ module Squared
473
484
  ver = nil
474
485
  `ruby --version`
475
486
  end)
487
+ break if workspace.windows?
488
+
476
489
  unless val.empty?
477
490
  out << trim.call(case cmd
478
491
  when 'chruby.sh'
@@ -521,8 +534,6 @@ module Squared
521
534
  case flag
522
535
  when :outdated
523
536
  cmd << gempwd << 'outdated'
524
- when :push
525
- cmd << 'push' << project
526
537
  else
527
538
  cmd << flag
528
539
  end
@@ -531,12 +542,9 @@ module Squared
531
542
  case flag
532
543
  when :install, :update
533
544
  list.concat(OPT_GEM[:install_base])
534
- first = ['=']
535
- when :uninstall, :pristine
536
- first = ['=']
537
545
  end
538
546
  cmd.merge(preopts)
539
- op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag], first: first)
547
+ op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag])
540
548
  op.each do |opt|
541
549
  if opt =~ op.values
542
550
  case $1
@@ -603,7 +611,7 @@ module Squared
603
611
  g = a.ljust(d)
604
612
  pat = [/^([^.]+\.)([^.]+\..+)$/, /^([^.]+\.[^.]+\.)(.+)$/]
605
613
  pre = b.start_with?('0.')
606
- latest = [theme[:current]]
614
+ latest = [theme[:latest]]
607
615
  case item.last
608
616
  when 1
609
617
  case filter
@@ -675,49 +683,76 @@ module Squared
675
683
  cmd.merge(update)
676
684
  run(cmd, banner: false, from: :'gem:update')
677
685
  end
678
- unless stdin?
679
- status = print_footer("major #{major} / minor #{minor} / patch #{patch}", right: true).split("\n")
680
- status[1] = sub_style(status[1], pat: /^( +major )(\d+)(.+)$/, styles: theme[:major], index: 2)
681
- status[1] = sub_style(status[1], pat: /^(.+)(minor )(\d+)(.+)$/, styles: theme[:active], index: 3)
682
- puts status
683
- end
686
+ print_status(major, minor, patch, from: :outdated)
684
687
  end
685
688
  on :last, from
686
689
  return
687
- when :build, :push
688
- if !op.empty?
689
- if flag == :build && op.size == 1
690
- op << shell_quote(path + op.first)
691
- else
692
- raise_error("unknown args: #{op.join(', ')}", hint: flag)
693
- end
694
- elsif flag == :build
690
+ when :build
691
+ if op.empty?
695
692
  spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *Dir.glob(path + '*.gemspec')]
696
693
  op << File.basename(spec) if (spec = spec.find { |file| File.exist?(file) })
694
+ else
695
+ op << shell_quote(path + op.shift)
696
+ op.clear(pass: false)
697
+ end
698
+ when :push
699
+ if op.empty?
700
+ op << shell_quote(path + choice_index('Select a file', Dir.glob('*.gem', base: path), force: true))
701
+ else
702
+ file = path + op.shift
703
+ raise_error("unknown args: #{op.join(', ')}", hint: flag) unless op.empty?
704
+ if file.exist?
705
+ op << shell_quote(file)
706
+ else
707
+ raise_error('gem not found', hint: file)
708
+ end
697
709
  end
710
+ run_rb(from: from, interactive: "Push #{sub_style(project, styles: theme[:active])}")
711
+ return
698
712
  when :exec
699
713
  raise_error('missing command', hint: flag) if op.empty?
700
- op << project << op.join(' ')
714
+ op << basic_option('gem', project) unless op.arg?('g', 'gem')
715
+ if (args = command_args(op.extras))
716
+ op.push(args)
717
+ end
718
+ op.append(delim: true, quote: false)
719
+ when :update
720
+ unless op.arg?('system')
721
+ op.push(project) if op.empty?
722
+ op.adjoin
723
+ end
724
+ op.clear(errors: true)
701
725
  else
702
- raise_error('missing gemname', hint: flag) if op.empty? && !op.arg?('system')
703
- if flag == :pristine
726
+ raise_error('missing gemname', hint: flag) if op.empty?
727
+ case flag
728
+ when :install, :uninstall, :pristine
729
+ post = readline('Enter command [args]', force: true) if flag == :install && op.extras.delete(':')
704
730
  if op.arg?('all')
705
- append_repeat 'skip', op.extras
706
- op.extras.clear
707
- elsif (n = op.first.index('@'))
708
- name = op.shift
709
- if n == 0
710
- op << project
731
+ if flag == :pristine
732
+ append_repeat 'skip', op.extras
733
+ op.reset
734
+ else
735
+ op.clear
736
+ end
737
+ elsif (n = op.extras.find_index { |val| val.match?(/(\A|[a-z])@\d/) })
738
+ items = op.extras.to_a
739
+ name = items.delete_at(n)
740
+ if (n = name.index('@')) == 0
741
+ pre = project
711
742
  ver = name[1..-1]
712
743
  else
713
- op << shell_escape(name[0, n])
714
- ver = name[n + 1..-1]
744
+ pre = name[0, n]
745
+ ver = name[(n + 1)..-1]
715
746
  end
716
- op << shell_option('version', ver)
717
- op.clear
747
+ op.adjoin(pre, shell_option('version', ver))
748
+ .clear(items)
749
+ .reset
750
+ elsif flag != :install
751
+ op.adjoin
718
752
  end
719
753
  end
720
754
  op.append.clear(errors: true)
755
+ op << '--' << post if post
721
756
  end
722
757
  run_rb(from: from)
723
758
  end
@@ -733,8 +768,12 @@ module Squared
733
768
  end
734
769
  case flag
735
770
  when 'exec', 'config'
736
- raise_error('no command args', hint: flag) if args.empty?
737
- cmd.merge(args)
771
+ if args.empty?
772
+ cmd << readline('Enter arguments', force: true)
773
+ else
774
+ args << command_args(args)
775
+ cmd.merge(args)
776
+ end
738
777
  else
739
778
  option_clear args
740
779
  end
@@ -754,14 +793,13 @@ module Squared
754
793
  run_s(args, banner: false, from: :rake)
755
794
  end
756
795
 
757
- def irb(name, opts = [], path: @path + 'lib', load: nil)
796
+ def irb(name, opts = [], path: @path + 'lib', args: nil)
758
797
  op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
759
- r = as_a name
760
- r.unshift('bundler/setup') unless load
761
- r.each { |val| op << shell_option('r', val, merge: true) }
762
- as_a(path).each { |val| op << quote_option('I', val, merge: true) }
763
- if load
764
- op << '--' << load
798
+ r = args ? [] : ['bundler/setup']
799
+ (r << name).each { |val| op << shell_option('r', val, merge: true) }
800
+ Array(path).each { |val| op << quote_option('I', val, merge: true) }
801
+ if args
802
+ op << '--' << args
765
803
  op.clear
766
804
  else
767
805
  op.append(delim: true)
@@ -854,7 +892,7 @@ module Squared
854
892
  private
855
893
 
856
894
  def run_rb(**kwargs)
857
- run(banner: !@session.include?('--quiet'), **kwargs)
895
+ run(banner: !@session&.include?('--quiet'), **kwargs)
858
896
  end
859
897
 
860
898
  def append_bundle(opts, list, target: @session, append: nil)
@@ -916,18 +954,16 @@ module Squared
916
954
  end
917
955
 
918
956
  def read_rakefile
919
- return @rakelist if @rakelist
920
-
921
- ret = []
922
- pwd = rakepwd
923
- pwd_set(pass: !pwd.nil?) do
924
- IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
925
- next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
957
+ @read_rakefile ||= [].tap do |ret|
958
+ pwd = rakepwd
959
+ pwd_set(pass: !pwd.nil?) do
960
+ IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
961
+ next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
926
962
 
927
- ret << [$1, $2]
963
+ ret << [$1, $2]
964
+ end
928
965
  end
929
966
  end
930
- @rakelist = ret
931
967
  end
932
968
 
933
969
  def preopts
@@ -943,19 +979,20 @@ module Squared
943
979
  end
944
980
 
945
981
  def rakefile
946
- return unless (file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? })
982
+ return @rakefile if @rakefile
947
983
 
948
- path + file
984
+ file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }
985
+ @rakefile = file ? path + file : ''
949
986
  end
950
987
 
951
988
  def rakepwd
952
- return unless Rake::VERSION >= '13.0.4'
989
+ return if pwd? || Rake::VERSION < '13.0.4'
953
990
 
954
991
  quote_option 'C', path
955
992
  end
956
993
 
957
994
  def gempwd
958
- return unless Gem::VERSION >= '3.4.2'
995
+ return if pwd? || Gem::VERSION < '3.4.2'
959
996
 
960
997
  quote_option 'C', path
961
998
  end
@@ -15,7 +15,7 @@ module Squared
15
15
  include Shell
16
16
  include Prompt
17
17
 
18
- def append(target, *args, delim: false, escape: false, quote: true)
18
+ def append(target, *args, delim: false, escape: false, quote: true, **)
19
19
  return if (ret = args.flatten).empty?
20
20
 
21
21
  target << '--' if delim && !target.include?('--')
@@ -47,7 +47,7 @@ module Squared
47
47
  val.map { |s| s.sub(/\A-([a-z\d])(.+)\z/i, '\1=\2').sub(/\A--?/, '') }.reject(&:empty?)
48
48
  end
49
49
 
50
- def arg?(target, *args, value: false)
50
+ def arg?(target, *args, value: false, **)
51
51
  r, s = args.partition { |val| val.is_a?(Regexp) }
52
52
  unless s.empty?
53
53
  s.map! { |val| Regexp.escape(shell_option(val)) }
@@ -139,6 +139,7 @@ module Squared
139
139
  numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) && pat.match?(v) } }
140
140
  skip = false
141
141
  opts.each do |opt|
142
+ next skip = true if opt == '--'
142
143
  next @extras << opt if skip
143
144
 
144
145
  if single&.match?(opt)
@@ -188,7 +189,8 @@ module Squared
188
189
  end
189
190
 
190
191
  def append(*args, **kwargs)
191
- OptionPartition.append(target, *(args.empty? ? extras : args), **kwargs)
192
+ args = extras if args.empty?
193
+ OptionPartition.append(target, *args, **kwargs)
192
194
  self
193
195
  end
194
196
 
@@ -205,6 +207,40 @@ module Squared
205
207
  self
206
208
  end
207
209
 
210
+ def adjoin(*args, start: false)
211
+ i = -1
212
+ (items = to_a).each_with_index do |val, index|
213
+ if i == 0
214
+ next unless val.start_with?('-')
215
+
216
+ i = index
217
+ break
218
+ elsif index > 0 && !val.start_with?('-')
219
+ if start
220
+ i = index + (start.is_a?(Numeric) ? start : 1)
221
+ break
222
+ end
223
+ i = 0
224
+ end
225
+ end
226
+ if i > 0
227
+ if args.empty?
228
+ args = dup
229
+ reset
230
+ end
231
+ args = items[0...i] + args + items[i..-1]
232
+ target.clear
233
+ end
234
+ merge(args)
235
+ self
236
+ end
237
+
238
+ def reset(errors: false)
239
+ extras.clear
240
+ clear(errors: true) if errors
241
+ self
242
+ end
243
+
208
244
  def arg?(*args, **kwargs)
209
245
  OptionPartition.arg?(target, *args, **kwargs)
210
246
  end
@@ -177,7 +177,8 @@ module Squared
177
177
  parse_opts.call(args)
178
178
  stage = 'init'
179
179
  puts if newline
180
- system("repo init -u #{env('REPO_URL') || manifest_url} -m #{args.manifest || target}.xml", chdir: root)
180
+ Common::System.shell("repo init -u #{env('REPO_URL') || manifest_url} -m #{args.manifest || target}.xml",
181
+ chdir: root)
181
182
  repo['all'].invoke
182
183
  end
183
184
 
@@ -3,8 +3,8 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  module Support
6
- RunData = Struct.new(:run, :block)
7
- ChainData = Struct.new(:action, :step, :with, :before, :after, :sync)
6
+ RunData = Struct.new('RunData', :run, :block)
7
+ ChainData = Struct.new('ChainData', :action, :step, :with, :before, :after, :sync)
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.12
4
+ version: 0.4.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham