squared 0.4.13 → 0.4.15

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,7 +4,7 @@ module Squared
4
4
  module Workspace
5
5
  module Project
6
6
  class Ruby < Git
7
- GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
7
+ GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb gems.rb Isolate].freeze
8
8
  DIR_RUBY = (GEMFILE + Rake::Application::DEFAULT_RAKEFILES + ['README.rdoc']).freeze
9
9
  OPT_RUBY = {
10
10
  ruby: %w[0=im? a c e=q E=bm F=qm i=bm? I=pm l n p r=bm s S w W=bm? x=pm? d|debug jit rjit v|verbose y|yydebug
@@ -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,10 +102,10 @@ module Squared
102
102
  end
103
103
  dependfile_set GEMFILE
104
104
  @autodetect = autodetect
105
- return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || (file = rakefile).nil?
105
+ return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || rakefile.empty?
106
106
 
107
107
  begin
108
- File.foreach(file) do |line|
108
+ File.foreach(rakefile) do |line|
109
109
  next unless line.match?(%r{\brequire\s+(["'])bundler/gem_tasks\1})
110
110
 
111
111
  cmd = bundle_output('exec rake').to_s
@@ -134,26 +134,36 @@ module Squared
134
134
  if flags.nil?
135
135
  case action
136
136
  when 'rake'
137
- next unless rakefile
137
+ next if rakefile.empty?
138
138
 
139
- format_desc action, nil, 'tasks*,opts*|^index|#,pattern*'
139
+ format_desc action, nil, "task+,opts*|#{indexchar}index+|#,pattern*"
140
140
  task action, [:command] do |_, args|
141
141
  if args.command == '#'
142
- format_list(read_rakefile, 'rake[^N]', 'tasks', grep: args.extras, from: rakefile.to_s,
143
- each: ->(val) { val[0] + val[1].to_s })
144
- elsif (n, opts = indexitem(args.command))
145
- list = read_rakefile
146
- if (item = list[n - 1])
147
- cmd = opts ? "#{opts} #{item.first}" : item.first
148
- elsif exception
149
- 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)
150
148
  else
151
- log.warn "rake task #{n} of #{list.size} (out of range)"
152
- 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
153
166
  end
154
- rake(args.extras.empty? ? cmd : cmd + shell_escape("[#{args.extras.join(',')}]"))
155
- else
156
- rake(opts: args.to_a)
157
167
  end
158
168
  end
159
169
  when 'irb'
@@ -163,16 +173,12 @@ module Squared
163
173
  format_desc action, nil, 'opts*,args*|:'
164
174
  task action do |_, args|
165
175
  args = args.to_a
166
- if args.last == ':'
167
- args.pop
168
- load = readline('Enter file and arguments', force: false)
169
- end
170
- irb(gemname, args, load: load)
176
+ irb(gemname, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
171
177
  end
172
178
  else
173
- format_desc(action, nil, OPT_BUNDLE[action.to_sym], after: case action
174
- when 'cache', 'check' then nil
175
- else 'command+' end)
179
+ format_desc(action, nil, 'opts*', before: case action
180
+ when 'cache', 'check' then nil
181
+ else 'command+' end)
176
182
  task action do |_, args|
177
183
  bundle(action, *args.to_a)
178
184
  end
@@ -194,20 +200,24 @@ module Squared
194
200
  case (filter = args.semver)
195
201
  when 'major', 'minor', 'patch', 'interactive', 'i'
196
202
  filter = 'interactive' if filter == 'i'
197
- args = args.to_a.drop(1)
203
+ args = args.extras
198
204
  else
199
205
  filter = nil
200
206
  args = args.to_a
201
207
  end
202
208
  gem!(flag, args, filter: filter)
203
209
  end
204
- when :build, :push, :exec
205
- 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)
206
216
  task flag do |_, args|
207
217
  gem! flag, args.to_a
208
218
  end
209
219
  else
210
- format_desc action, flag, "opts*,name+#{flag == :pristine ? '|name?@version' : ''}"
220
+ format_desc(action, flag, 'opts*', after: flag == :pristine ? 'name*|name?@version' : 'name*')
211
221
  task flag do |_, args|
212
222
  args = param_guard(action, flag, args: args.to_a)
213
223
  gem! flag, args
@@ -219,19 +229,18 @@ module Squared
219
229
  format_desc action, flag, 'path,opts*,args*'
220
230
  task flag, [:rb] do |_, args|
221
231
  file = args.rb
222
- args = args.to_a.drop(1)
232
+ args = args.extras
223
233
  unless file && !file.include?('*')
224
- values = ['Arguments']
225
- values.unshift('Options') unless file
226
- file, opts, extra = choice_index('Select a file', Dir.glob(file || '*.rb', base: path),
227
- values: values, force: true, series: !args.include?('v'))
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'))
228
237
  if file
229
- extra = opts
238
+ prog = opts
230
239
  else
231
240
  args.concat(OptionPartition.strip(opts))
232
241
  end
233
242
  end
234
- ruby(flag, args, file: file, args: extra)
243
+ ruby(flag, args, file: file, args: prog)
235
244
  end
236
245
  when :script
237
246
  format_desc action, flag, 'opts*,args*'
@@ -285,8 +294,8 @@ module Squared
285
294
  on :first, :copy
286
295
  dest = Pathname.new(into).realpath
287
296
  print_item unless @output[0] || task_invoked?(/^copy(?::#{Ruby.ref}|$)/)
288
- glob = as_a(glob || '**/*')
289
- as_a(from).each_with_index do |val, i|
297
+ glob = Array(glob || '**/*')
298
+ Array(from).each_with_index do |val, i|
290
299
  a = path + val
291
300
  b = dest + val
292
301
  c = glob[i] || glob.first
@@ -475,6 +484,8 @@ module Squared
475
484
  ver = nil
476
485
  `ruby --version`
477
486
  end)
487
+ break if workspace.windows?
488
+
478
489
  unless val.empty?
479
490
  out << trim.call(case cmd
480
491
  when 'chruby.sh'
@@ -523,8 +534,6 @@ module Squared
523
534
  case flag
524
535
  when :outdated
525
536
  cmd << gempwd << 'outdated'
526
- when :push
527
- cmd << 'push' << project
528
537
  else
529
538
  cmd << flag
530
539
  end
@@ -533,12 +542,9 @@ module Squared
533
542
  case flag
534
543
  when :install, :update
535
544
  list.concat(OPT_GEM[:install_base])
536
- first = ['=']
537
- when :uninstall, :pristine
538
- first = ['=']
539
545
  end
540
546
  cmd.merge(preopts)
541
- 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])
542
548
  op.each do |opt|
543
549
  if opt =~ op.values
544
550
  case $1
@@ -677,26 +683,32 @@ module Squared
677
683
  cmd.merge(update)
678
684
  run(cmd, banner: false, from: :'gem:update')
679
685
  end
680
- unless stdin?
681
- status = print_footer("major #{major} / minor #{minor} / patch #{patch}", right: true).split("\n")
682
- status[1] = sub_style(status[1], pat: /^( +major )(\d+)(.+)$/, styles: theme[:major], index: 2)
683
- status[1] = sub_style(status[1], pat: /^(.+)(minor )(\d+)(.+)$/, styles: theme[:active], index: 3)
684
- puts status
685
- end
686
+ print_status(major, minor, patch, from: :outdated)
686
687
  end
687
688
  on :last, from
688
689
  return
689
- when :build, :push
690
- if !op.empty?
691
- if flag == :build && op.size == 1
692
- op << shell_quote(path + op.first)
693
- else
694
- raise_error("unknown args: #{op.join(', ')}", hint: flag)
695
- end
696
- elsif flag == :build
690
+ when :build
691
+ if op.empty?
697
692
  spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *Dir.glob(path + '*.gemspec')]
698
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)
699
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
709
+ end
710
+ run_rb(from: from, interactive: "Push #{sub_style(project, styles: theme[:active])}")
711
+ return
700
712
  when :exec
701
713
  raise_error('missing command', hint: flag) if op.empty?
702
714
  op << basic_option('gem', project) unless op.arg?('g', 'gem')
@@ -704,26 +716,43 @@ module Squared
704
716
  op.push(args)
705
717
  end
706
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)
707
725
  else
708
- raise_error('missing gemname', hint: flag) if op.empty? && !op.arg?('system')
709
- 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(':')
710
730
  if op.arg?('all')
711
- append_repeat 'skip', op.extras
712
- op.extras.clear
713
- elsif (n = op.first.index('@'))
714
- name = op.shift
715
- if n == 0
716
- 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
717
742
  ver = name[1..-1]
718
743
  else
719
- op << shell_escape(name[0, n])
720
- ver = name[n + 1..-1]
744
+ pre = name[0, n]
745
+ ver = name[(n + 1)..-1]
721
746
  end
722
- op << shell_option('version', ver)
723
- op.clear
747
+ op.adjoin(pre, shell_option('version', ver))
748
+ .clear(items)
749
+ .reset
750
+ elsif flag != :install
751
+ op.adjoin
724
752
  end
725
753
  end
726
754
  op.append.clear(errors: true)
755
+ op << '--' << post if post
727
756
  end
728
757
  run_rb(from: from)
729
758
  end
@@ -764,14 +793,13 @@ module Squared
764
793
  run_s(args, banner: false, from: :rake)
765
794
  end
766
795
 
767
- def irb(name, opts = [], path: @path + 'lib', load: nil)
796
+ def irb(name, opts = [], path: @path + 'lib', args: nil)
768
797
  op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
769
- r = as_a name
770
- r.unshift('bundler/setup') unless load
771
- r.each { |val| op << shell_option('r', val, merge: true) }
772
- as_a(path).each { |val| op << quote_option('I', val, merge: true) }
773
- if load
774
- 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
775
803
  op.clear
776
804
  else
777
805
  op.append(delim: true)
@@ -821,18 +849,20 @@ module Squared
821
849
  pwd_set(pass: !pwd.nil?) do
822
850
  out = `#{gem_output(pwd, 'list --local -d', project)}`
823
851
  if out =~ /#{Regexp.escape(project)} \(([^)]+)\)/
824
- ver = $1.split(/\s*,\s*/)
825
- ver.unshift(@version).uniq!
826
- ver.each do |val|
827
- next unless out =~ /\(#{Regexp.escape(val)}(?:,[^)]+|\b)\):([^\n]+)/
828
-
829
- set.call(val, $1)
830
- break
831
- end
852
+ $1.split(/\s*,\s*/)
853
+ .unshift(@version)
854
+ .uniq
855
+ .each do |val|
856
+ next unless out =~ /\(#{Regexp.escape(val)}(?:,[^)]+|\b)\):([^\n]+)/
857
+
858
+ set.call(val, $1)
859
+ return gemdir? if @gemdir
860
+ end
832
861
  end
833
862
  end
834
- end
835
- unless @gemdir
863
+ require 'rubygems'
864
+ @gemdir = Pathname.new(Gem.dir) + gempath
865
+ else
836
866
  parse = lambda do |path|
837
867
  next unless path
838
868
 
@@ -845,9 +875,10 @@ module Squared
845
875
  target = RUBY_VERSION.start_with?('2.6') ? RubyVM : $LOAD_PATH
846
876
  parse.call(target.resolve_feature_path(project)&.last)
847
877
  end
848
- pwd_set { parse.call(`#{bundle_output('show', project)}`) } unless @gemdir
878
+ if !@gemdir && !pwd_set { parse.call(`#{bundle_output('show', project)}`) }
879
+ raise_error 'gems directory not found'
880
+ end
849
881
  end
850
- raise_error('parse failed', hint: @version || 'path') unless @gemdir
851
882
  rescue StandardError => e
852
883
  log.error e
853
884
  @version = nil
@@ -864,7 +895,7 @@ module Squared
864
895
  private
865
896
 
866
897
  def run_rb(**kwargs)
867
- run(banner: !@session.include?('--quiet'), **kwargs)
898
+ run(banner: !@session&.include?('--quiet'), **kwargs)
868
899
  end
869
900
 
870
901
  def append_bundle(opts, list, target: @session, append: nil)
@@ -926,18 +957,16 @@ module Squared
926
957
  end
927
958
 
928
959
  def read_rakefile
929
- return @rakelist if @rakelist
930
-
931
- ret = []
932
- pwd = rakepwd
933
- pwd_set(pass: !pwd.nil?) do
934
- IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
935
- next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
960
+ @read_rakefile ||= [].tap do |ret|
961
+ pwd = rakepwd
962
+ pwd_set(pass: !pwd.nil?) do
963
+ IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
964
+ next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
936
965
 
937
- ret << [$1, $2]
966
+ ret << [$1, $2]
967
+ end
938
968
  end
939
969
  end
940
- @rakelist = ret
941
970
  end
942
971
 
943
972
  def preopts
@@ -953,19 +982,20 @@ module Squared
953
982
  end
954
983
 
955
984
  def rakefile
956
- return unless (file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? })
985
+ return @rakefile if @rakefile
957
986
 
958
- path + file
987
+ file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }
988
+ @rakefile = file ? path + file : ''
959
989
  end
960
990
 
961
991
  def rakepwd
962
- return unless Rake::VERSION >= '13.0.4'
992
+ return if pwd? || Rake::VERSION < '13.0.4'
963
993
 
964
994
  quote_option 'C', path
965
995
  end
966
996
 
967
997
  def gempwd
968
- return unless Gem::VERSION >= '3.4.2'
998
+ return if pwd? || Gem::VERSION < '3.4.2'
969
999
 
970
1000
  quote_option 'C', path
971
1001
  end
@@ -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
 
@@ -10,16 +10,16 @@ module Squared
10
10
 
11
11
  TASK_BASE = []
12
12
  TASK_BATCH = {}
13
- TASK_EXTEND = {}
13
+ TASK_EXTEND = Workspace.hashlist
14
14
  TASK_KEYS = []
15
- TASK_ALIAS = {}
15
+ TASK_ALIAS = Workspace.hashobj
16
16
  TASK_NAME = {}
17
17
  private_constant :TASK_BASE, :TASK_BATCH, :TASK_EXTEND, :TASK_KEYS, :TASK_ALIAS, :TASK_NAME
18
18
 
19
19
  class << self
20
20
  def add(task, obj)
21
21
  key_set task
22
- (TASK_EXTEND[task] ||= []) << obj
22
+ TASK_EXTEND[task] << obj
23
23
  end
24
24
 
25
25
  def batch(*args, obj)
@@ -37,7 +37,7 @@ module Squared
37
37
 
38
38
  def alias(ref, obj)
39
39
  if obj.is_a?(Hash)
40
- obj.each { |key, val| (TASK_ALIAS[key] ||= {})[ref] = val }
40
+ obj.each { |key, val| TASK_ALIAS[key][ref] = val }
41
41
  else
42
42
  TASK_ALIAS[obj]&.delete(ref)
43
43
  end
@@ -79,8 +79,8 @@ module Squared
79
79
  @chain = {}
80
80
  @exclude = exclude.freeze
81
81
  @session = {
82
- group: {},
83
- parent: {},
82
+ group: Workspace.hashlist,
83
+ parent: Workspace.hashlist,
84
84
  id: []
85
85
  }
86
86
  @data = {}
@@ -95,7 +95,7 @@ module Squared
95
95
 
96
96
  if (g = proj.group)
97
97
  id << g
98
- (group[:"#{key}:#{g}"] ||= []).concat(tasks)
98
+ group[:"#{key}:#{g}"].concat(tasks)
99
99
  else
100
100
  items.concat(tasks)
101
101
  end
@@ -106,7 +106,7 @@ module Squared
106
106
  next unless (b = ws.find_base(proj)) && (n = b.ref.to_s) != g
107
107
 
108
108
  id << n
109
- (parent[:"#{key}:#{n}"] ||= []).concat(tasks)
109
+ parent[:"#{key}:#{n}"].concat(tasks)
110
110
  end
111
111
  end
112
112
 
@@ -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
@@ -27,6 +27,14 @@ module Squared
27
27
  !!project(name)&.enabled?
28
28
  end
29
29
 
30
+ def hashobj
31
+ Hash.new { |data, key| data[key] = {} }
32
+ end
33
+
34
+ def hashlist
35
+ Hash.new { |data, key| data[key] = [] }
36
+ end
37
+
30
38
  private
31
39
 
32
40
  def project(name)
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.13
4
+ version: 0.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham