squared 0.5.0 → 0.5.1

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,
@@ -102,11 +102,10 @@ module Squared
102
102
  end
103
103
  dependfile_set GEMFILE
104
104
  @autodetect = autodetect
105
- @rakelist = nil
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,args*' : 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
@@ -220,19 +229,18 @@ module Squared
220
229
  format_desc action, flag, 'path,opts*,args*'
221
230
  task flag, [:rb] do |_, args|
222
231
  file = args.rb
223
- args = args.to_a.drop(1)
232
+ args = args.extras
224
233
  unless file && !file.include?('*')
225
- values = ['Arguments']
226
- values.prepend('Options') unless file
227
- file, opts, extra = choice_index('Select a file', Dir.glob(file || '*.rb', base: path),
228
- values: values, force: true, series: !args.include?('v'))
234
+ file, opts, prog = choice_index('Select a file', Dir.glob(file || '*.rb', base: path),
235
+ values: (file ? [] : ['Options']) << 'Arguments',
236
+ force: true, series: !args.include?('v'))
229
237
  if file
230
- extra = opts
238
+ prog = opts
231
239
  else
232
240
  args.concat(OptionPartition.strip(opts))
233
241
  end
234
242
  end
235
- ruby(flag, args, file: file, args: extra)
243
+ ruby(flag, args, file: file, args: prog)
236
244
  end
237
245
  when :script
238
246
  format_desc action, flag, 'opts*,args*'
@@ -286,8 +294,8 @@ module Squared
286
294
  on :first, :copy
287
295
  dest = Pathname.new(into).realpath
288
296
  print_item unless @output[0] || task_invoked?(/^copy(?::#{Ruby.ref}|$)/)
289
- glob = as_a(glob || '**/*')
290
- as_a(from).each_with_index do |val, i|
297
+ glob = Array(glob || '**/*')
298
+ Array(from).each_with_index do |val, i|
291
299
  a = path + val
292
300
  b = dest + val
293
301
  c = glob[i] || glob.first
@@ -296,7 +304,7 @@ module Squared
296
304
  copy_dir(a, b, c, pass: pass, verbose: verbose)
297
305
  rescue StandardError => e
298
306
  log.error e
299
- ret = on(:error, :copy, e)
307
+ ret = on :error, :copy, e
300
308
  raise if exception && ret != true
301
309
  end
302
310
  end
@@ -385,7 +393,7 @@ module Squared
385
393
  index: 2)
386
394
  end
387
395
  end
388
- out.call("#{start.to_s.rjust(2)}. #{line}")
396
+ out.call('%2d. %s' % [start, line])
389
397
  elsif line.start_with?('Gem')
390
398
  unless stdin?
391
399
  sub = { pat: /^(.+)(?<!\dm)(Gem|Latest)(.+)$/, styles: theme[:header], index: 2 }
@@ -477,6 +485,8 @@ module Squared
477
485
  ver = nil
478
486
  `ruby --version`
479
487
  end)
488
+ break if workspace.windows?
489
+
480
490
  unless val.empty?
481
491
  out << trim.call(case cmd
482
492
  when 'chruby.sh'
@@ -513,7 +523,7 @@ module Squared
513
523
  end
514
524
  out.map!(&:split)
515
525
  pad = out.map(&:first).map!(&:size).max
516
- puts(out.map! { |line| "#{line.first.rjust(pad)} #{line[1..-1].join(' ')}" })
526
+ puts(out.map! { |line| '%*s %s' % [pad, line.first, line[1..-1].join(' ')] })
517
527
  end
518
528
  return
519
529
  end
@@ -525,8 +535,6 @@ module Squared
525
535
  case flag
526
536
  when :outdated
527
537
  cmd << gempwd << 'outdated'
528
- when :push
529
- cmd << 'push' << project
530
538
  else
531
539
  cmd << flag
532
540
  end
@@ -535,12 +543,9 @@ module Squared
535
543
  case flag
536
544
  when :install, :update
537
545
  list.concat(OPT_GEM[:install_base])
538
- first = ['=']
539
- when :uninstall, :pristine
540
- first = ['=']
541
546
  end
542
547
  cmd.merge(preopts)
543
- op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag], first: first)
548
+ op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag])
544
549
  op.each do |opt|
545
550
  if opt =~ op.values
546
551
  case $1
@@ -597,7 +602,7 @@ module Squared
597
602
 
598
603
  a, b, c = item.first
599
604
  if i == 0
600
- line = "#{' #'.ljust(pad)} #{a.ljust(d)} #{b.rjust(e)} #{c.rjust(f)}"
605
+ line = '%-*s %-*s %*s %*s' % [pad, ' #', d, a, e, b, f, c]
601
606
  n = line.size
602
607
  2.times do
603
608
  line = sub_style(line, pat: /^(.+)(?<!\dm)(#{a}|#{c})(.*)$/, styles: theme[:header], index: 2)
@@ -648,7 +653,7 @@ module Squared
648
653
  puts queue
649
654
  queue = nil
650
655
  end
651
- puts "#{"#{j}.".rjust(pad)} #{g} #{b} #{h}"
656
+ puts '%*s %s %s %s' % [pad, "#{j}.", g, b, h]
652
657
  update << a if filter == 'interactive' && confirm_outdated(a, c, item.last)
653
658
  end
654
659
  end
@@ -678,31 +683,32 @@ module Squared
678
683
  cmd.merge(update)
679
684
  run(cmd, banner: false, from: :'gem:update')
680
685
  end
681
- unless stdin?
682
- status = print_footer("major #{major} / minor #{minor} / patch #{patch}", right: true).split("\n")
683
- status[1] = status[1]
684
- .yield_self do |s|
685
- sub_style(s, pat: /^( +major )(\d+)(.+)$/, styles: theme[:major], index: 2)
686
- end
687
- .yield_self do |s|
688
- sub_style(s, pat: /^(.+)(minor )(\d+)(.+)$/, styles: theme[:active], index: 3)
689
- end
690
- puts status
691
- end
686
+ print_status(major, minor, patch, from: :outdated)
692
687
  end
693
688
  on :last, from
694
689
  return
695
- when :build, :push
696
- if !op.empty?
697
- if flag == :build && op.size == 1
698
- op << shell_quote(path + op.first)
699
- else
700
- raise_error("unknown args: #{op.join(', ')}", hint: flag)
701
- end
702
- elsif flag == :build
690
+ when :build
691
+ if op.empty?
703
692
  spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *path.glob('*.gemspec')]
704
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
705
709
  end
710
+ run_rb(from: from, interactive: "Push #{sub_style(project, styles: theme[:active])}")
711
+ return
706
712
  when :exec
707
713
  raise_error('missing command', hint: flag) if op.empty?
708
714
  op << basic_option('gem', project) unless op.arg?('g', 'gem')
@@ -710,26 +716,43 @@ module Squared
710
716
  op.push(args)
711
717
  end
712
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)
713
725
  else
714
- raise_error('missing gemname', hint: flag) if op.empty? && !op.arg?('system')
715
- 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(':')
716
730
  if op.arg?('all')
717
- append_repeat 'skip', op.extras
718
- op.extras.clear
719
- elsif (n = op.first.index('@'))
720
- name = op.shift
721
- if n == 0
722
- 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
723
742
  ver = name[1..-1]
724
743
  else
725
- op << shell_escape(name[0, n])
726
- ver = name[n + 1..-1]
744
+ pre = name[0, n]
745
+ ver = name[(n + 1)..-1]
727
746
  end
728
- op << shell_option('version', ver)
729
- op.clear
747
+ op.adjoin(pre, shell_option('version', ver))
748
+ .clear(items)
749
+ .reset
750
+ elsif flag != :install
751
+ op.adjoin
730
752
  end
731
753
  end
732
754
  op.append.clear(errors: true)
755
+ op << '--' << post if post
733
756
  end
734
757
  run_rb(from: from)
735
758
  end
@@ -770,14 +793,13 @@ module Squared
770
793
  run_s(args, banner: false, from: :rake)
771
794
  end
772
795
 
773
- def irb(name, opts = [], path: @path + 'lib', load: nil)
796
+ def irb(name, opts = [], path: @path + 'lib', args: nil)
774
797
  op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
775
- r = as_a name
776
- r.prepend('bundler/setup') unless load
777
- r.each { |val| op << shell_option('r', val, merge: true) }
778
- as_a(path).each { |val| op << quote_option('I', val, merge: true) }
779
- if load
780
- 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
781
803
  op.clear
782
804
  else
783
805
  op.append(delim: true)
@@ -871,7 +893,7 @@ module Squared
871
893
  private
872
894
 
873
895
  def run_rb(**kwargs)
874
- run(banner: !@session.include?('--quiet'), **kwargs)
896
+ run(banner: !@session&.include?('--quiet'), **kwargs)
875
897
  end
876
898
 
877
899
  def append_bundle(opts, list, target: @session, append: nil)
@@ -933,18 +955,16 @@ module Squared
933
955
  end
934
956
 
935
957
  def read_rakefile
936
- return @rakelist if @rakelist
937
-
938
- ret = []
939
- pwd = rakepwd
940
- pwd_set(pass: !pwd.nil?) do
941
- IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
942
- next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
958
+ @read_rakefile ||= [].tap do |ret|
959
+ pwd = rakepwd
960
+ pwd_set(pass: !pwd.nil?) do
961
+ IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
962
+ next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
943
963
 
944
- ret << [$1, $2]
964
+ ret << [$1, $2]
965
+ end
945
966
  end
946
967
  end
947
- @rakelist = ret
948
968
  end
949
969
 
950
970
  def preopts
@@ -960,19 +980,19 @@ module Squared
960
980
  end
961
981
 
962
982
  def rakefile
963
- return unless (file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? })
964
-
965
- path + file
983
+ @rakefile ||= Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }.yield_self do |file|
984
+ file ? path + file : ''
985
+ end
966
986
  end
967
987
 
968
988
  def rakepwd
969
- return unless Rake::VERSION >= '13.0.4'
989
+ return if pwd? || Rake::VERSION < '13.0.4'
970
990
 
971
991
  quote_option 'C', path
972
992
  end
973
993
 
974
994
  def gempwd
975
- return unless Gem::VERSION >= '3.4.2'
995
+ return if pwd? || Gem::VERSION < '3.4.2'
976
996
 
977
997
  quote_option 'C', path
978
998
  end
@@ -35,7 +35,7 @@ module Squared
35
35
  kwargs[:hint] ||= 'unrecognized'
36
36
  append(target, opts, delim: true) if kwargs.delete(:append)
37
37
  warn log_message(Logger::WARN, opts.join(', '), pass: true, **kwargs)
38
- return if pass || confirm("Run? [#{sub_style(target, styles: styles)}] [y/N] ", 'N')
38
+ return if pass || confirm("Run? [#{sub_style(target, styles: styles)}]", 'N')
39
39
 
40
40
  raise_error 'user cancelled'
41
41
  end
@@ -140,6 +140,7 @@ module Squared
140
140
  numcheck = ->(k, v) { numtype.any? { |flag, pat| flag.include?(k) && pat.match?(v) } }
141
141
  skip = false
142
142
  opts.each do |opt|
143
+ next skip = true if opt == '--'
143
144
  next @extras << opt if skip
144
145
 
145
146
  if single&.match?(opt)
@@ -189,7 +190,8 @@ module Squared
189
190
  end
190
191
 
191
192
  def append(*args, **kwargs)
192
- OptionPartition.append(target, *(args.empty? ? extras : args), **kwargs)
193
+ args = extras if args.empty?
194
+ OptionPartition.append(target, *args, **kwargs)
193
195
  self
194
196
  end
195
197
 
@@ -206,6 +208,40 @@ module Squared
206
208
  self
207
209
  end
208
210
 
211
+ def adjoin(*args, start: false)
212
+ i = -1
213
+ (items = to_a).each_with_index do |val, index|
214
+ if i == 0
215
+ next unless val.start_with?('-')
216
+
217
+ i = index
218
+ break
219
+ elsif index > 0 && !val.start_with?('-')
220
+ if start
221
+ i = index + (start.is_a?(Numeric) ? start : 1)
222
+ break
223
+ end
224
+ i = 0
225
+ end
226
+ end
227
+ if i > 0
228
+ if args.empty?
229
+ args = dup
230
+ reset
231
+ end
232
+ args = items[0...i] + args + items[i..-1]
233
+ target.clear
234
+ end
235
+ merge(args)
236
+ self
237
+ end
238
+
239
+ def reset(errors: false)
240
+ extras.clear
241
+ clear(errors: true) if errors
242
+ self
243
+ end
244
+
209
245
  def arg?(*args, **kwargs)
210
246
  OptionPartition.arg?(target, *args, **kwargs)
211
247
  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
 
@@ -214,7 +215,7 @@ module Squared
214
215
 
215
216
  path = sub_style(root, styles: theme[:inline])
216
217
  @repo_override = Common::Prompt.confirm(
217
- "#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation? [y/N] ",
218
+ "#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation?",
218
219
  'N',
219
220
  timeout: env('REPO_TIMEOUT', 15, ignore: '0')
220
221
  )
@@ -3,9 +3,9 @@
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)
8
- BannerData = Struct.new(:command, :order, :styles, :border)
6
+ RunData = Struct.new('RunData', :run, :block)
7
+ ChainData = Struct.new('ChainData', :action, :step, :with, :before, :after, :sync)
8
+ BannerData = Struct.new('BannerData', :command, :order, :styles, :border)
9
9
  end
10
10
  end
11
11
  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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham