squared 0.4.15 → 0.4.17

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.
@@ -91,7 +91,7 @@ module Squared
91
91
  'irb' => nil
92
92
  })
93
93
 
94
- def initialize(*, autodetect: false, **kwargs)
94
+ def initialize(*, autodetect: false, gemspec: nil, **kwargs)
95
95
  super
96
96
  if @pass.include?(Ruby.ref)
97
97
  initialize_ref Ruby.ref
@@ -102,7 +102,8 @@ module Squared
102
102
  end
103
103
  dependfile_set GEMFILE
104
104
  @autodetect = autodetect
105
- return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || rakefile.empty?
105
+ @gemfile = path + gemspec if gemspec
106
+ return if !@output[0].nil? || !@copy.nil? || version || @autodetect || !rakefile
106
107
 
107
108
  begin
108
109
  File.foreach(rakefile) do |line|
@@ -125,16 +126,16 @@ module Squared
125
126
 
126
127
  def populate(*, **)
127
128
  super
128
- return unless outdated? && ref?(Ruby.ref)
129
+ return unless (outdated? && ref?(Ruby.ref)) || @only
129
130
 
130
131
  namespace name do
131
132
  Ruby.subtasks do |action, flags|
132
- next if @pass.include?(action)
133
+ next if task_pass?(action)
133
134
 
134
135
  if flags.nil?
135
136
  case action
136
137
  when 'rake'
137
- next if rakefile.empty?
138
+ next unless rakefile
138
139
 
139
140
  format_desc action, nil, "task+,opts*|#{indexchar}index+|#,pattern*"
140
141
  task action, [:command] do |_, args|
@@ -167,13 +168,11 @@ module Squared
167
168
  end
168
169
  end
169
170
  when 'irb'
170
- next unless (spec = basepath("#{project}.gemspec") || basepath("#{name}.gemspec"))
171
- next unless basepath('lib').join("#{gemname = stripext(spec)}.rb").exist?
172
-
173
171
  format_desc action, nil, 'opts*,args*|:'
174
172
  task action do |_, args|
175
173
  args = args.to_a
176
- irb(gemname, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
174
+ name = gemlib.any? { |file| basepath(file).join("#{gemname}.rb").exist? } ? gemname : nil
175
+ irb(name, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
177
176
  end
178
177
  else
179
178
  format_desc(action, nil, 'opts*', before: case action
@@ -276,7 +275,7 @@ module Squared
276
275
  end
277
276
  end
278
277
 
279
- def copy(from: 'lib', into: @gemdir, override: false, **kwargs)
278
+ def copy(from: gemlib, into: @gemdir, override: false, **kwargs)
280
279
  glob = kwargs[:include]
281
280
  pass = kwargs[:exclude]
282
281
  if @copy && !override
@@ -303,9 +302,7 @@ module Squared
303
302
  begin
304
303
  copy_dir(a, b, c, pass: pass, verbose: verbose)
305
304
  rescue StandardError => e
306
- log.error e
307
- ret = on(:error, :copy, e)
308
- raise if exception && ret != true
305
+ on_error e, :copy
309
306
  end
310
307
  end
311
308
  on :last, :copy
@@ -445,11 +442,11 @@ module Squared
445
442
  when :file, :script
446
443
  op = OptionPartition.new(opts, OPT_RUBY[:ruby], ruby_session, project: self, args: true)
447
444
  if file
448
- op.extras.unshift(shell_quote(path + file))
445
+ op.unshift(shell_quote(path + file))
449
446
  elsif command
450
447
  op << quote_option('e', command, option: false)
451
448
  end
452
- op.extras << args if (args = ENV.fetch('RUBY_ARGS', args))
449
+ op.push(args) if (args = ENV.fetch('RUBY_ARGS', args))
453
450
  op.append(delim: true, escape: false, quote: false) unless op.empty?
454
451
  when :version
455
452
  pwd_set do
@@ -568,7 +565,7 @@ module Squared
568
565
  minor = 0
569
566
  patch = 0
570
567
  update = []
571
- pwd_set(pass: !pwd.nil?, from: from) do
568
+ pwd_set(pass: !gempwd.nil?, from: from) do
572
569
  items = [[%w[Gem Current Latest], nil]]
573
570
  IO.popen(cmd.done).each do |line|
574
571
  if line =~ /^(\S+) \((\S+) < ([^)]+)\)$/
@@ -689,36 +686,43 @@ module Squared
689
686
  return
690
687
  when :build
691
688
  if op.empty?
692
- spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *Dir.glob(path + '*.gemspec')]
693
- op << File.basename(spec) if (spec = spec.find { |file| File.exist?(file) })
689
+ op.add_path(gemfile)
694
690
  else
695
- op << shell_quote(path + op.shift)
696
- op.clear(pass: false)
691
+ op.add_path(op.shift)
692
+ .clear(pass: false)
697
693
  end
698
694
  when :push
699
695
  if op.empty?
700
- op << shell_quote(path + choice_index('Select a file', Dir.glob('*.gem', base: path), force: true))
696
+ file = path + (if (spec = gemspec)
697
+ "#{spec.name}-#{spec.version}.gem"
698
+ else
699
+ choice_index('Select a file', Dir.glob('*.gem', base: path), force: true)
700
+ end)
701
701
  else
702
702
  file = path + op.shift
703
+ raise_error('gem not found', hint: file) unless file.exist?
703
704
  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
705
  end
710
- run_rb(from: from, interactive: "Push #{sub_style(project, styles: theme[:active])}")
706
+ op.add_path(file)
707
+ run_rb(from: from, interactive: "Push #{sub_style(gemname, styles: theme[:active])}")
711
708
  return
712
709
  when :exec
713
- raise_error('missing command', hint: flag) if op.empty?
714
- op << basic_option('gem', project) unless op.arg?('g', 'gem')
715
- if (args = command_args(op.extras))
710
+ min = if op.arg?('g', 'gem')
711
+ 1
712
+ elsif op.empty?
713
+ op << basic_option('gem', gemname)
714
+ 1
715
+ else
716
+ op << op.shift
717
+ 0
718
+ end
719
+ if (args = command_args(op.extras, min: min, force: min == 1 && op.empty?))
716
720
  op.push(args)
717
721
  end
718
- op.append(delim: true, quote: false)
722
+ op.append(quote: false)
719
723
  when :update
720
724
  unless op.arg?('system')
721
- op.push(project) if op.empty?
725
+ op.push(gemname) if op.empty?
722
726
  op.adjoin
723
727
  end
724
728
  op.clear(errors: true)
@@ -726,7 +730,7 @@ module Squared
726
730
  raise_error('missing gemname', hint: flag) if op.empty?
727
731
  case flag
728
732
  when :install, :uninstall, :pristine
729
- post = readline('Enter command [args]', force: true) if flag == :install && op.extras.delete(':')
733
+ post = readline('Enter command [args]', force: true) if flag == :install && op.remove(':')
730
734
  if op.arg?('all')
731
735
  if flag == :pristine
732
736
  append_repeat 'skip', op.extras
@@ -738,7 +742,7 @@ module Squared
738
742
  items = op.extras.to_a
739
743
  name = items.delete_at(n)
740
744
  if (n = name.index('@')) == 0
741
- pre = project
745
+ pre = gemname
742
746
  ver = name[1..-1]
743
747
  else
744
748
  pre = name[0, n]
@@ -793,10 +797,11 @@ module Squared
793
797
  run_s(args, banner: false, from: :rake)
794
798
  end
795
799
 
796
- def irb(name, opts = [], path: @path + 'lib', args: nil)
800
+ def irb(name = nil, opts = [], path: gemlib, args: nil)
797
801
  op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
798
802
  r = args ? [] : ['bundler/setup']
799
- (r << name).each { |val| op << shell_option('r', val, merge: true) }
803
+ r << name if name
804
+ r.each { |val| op << shell_option('r', val, merge: true) }
800
805
  Array(path).each { |val| op << quote_option('I', val, merge: true) }
801
806
  if args
802
807
  op << '--' << args
@@ -807,6 +812,23 @@ module Squared
807
812
  run(banner: false)
808
813
  end
809
814
 
815
+ def gemspec
816
+ return @gemspec unless @gemspec.nil?
817
+
818
+ begin
819
+ if (file = gemfile)
820
+ @gemspec = Gem::Specification.load(file.to_s)
821
+ end
822
+ rescue StandardError => e
823
+ log.debug e
824
+ end
825
+ @gemspec ||= false
826
+ end
827
+
828
+ def gemname
829
+ @gemname ||= ((spec = gemspec) ? spec.name : project)
830
+ end
831
+
810
832
  def depend?
811
833
  @depend != false && (!@depend.nil? || outdated?)
812
834
  end
@@ -815,7 +837,7 @@ module Squared
815
837
  return true if super || (@copy.is_a?(Hash) && copy.fetch(:into, nil))
816
838
  return gemdir? if @gemdir
817
839
 
818
- if @version
840
+ if version
819
841
  begin
820
842
  case @autodetect
821
843
  when 'rvm'
@@ -840,15 +862,17 @@ module Squared
840
862
  return false unless @autodetect
841
863
 
842
864
  set = lambda do |val, path|
843
- log.warn "using version #{val} (given #{@version})" if @version && @version != val
844
- @version = val
865
+ if (ver = version) && ver != val
866
+ log.warn "using version #{val} (given #{ver})"
867
+ end
868
+ self.version = val
845
869
  @gemdir = Pathname.new(path.strip) + gempath
846
870
  end
847
- if @version
848
- pwd = gempwd
849
- pwd_set(pass: !pwd.nil?) do
850
- out = `#{gem_output(pwd, 'list --local -d', project)}`
851
- if out =~ /#{Regexp.escape(project)} \(([^)]+)\)/
871
+ if version
872
+ opt = gempwd
873
+ pwd_set(pass: !opt.nil?) do
874
+ out = `#{gem_output(opt, 'list --local -d', gemname)}`
875
+ if out =~ /#{Regexp.escape(gemname)} \(([^)]+)\)/
852
876
  $1.split(/\s*,\s*/)
853
877
  .unshift(@version)
854
878
  .uniq
@@ -860,22 +884,21 @@ module Squared
860
884
  end
861
885
  end
862
886
  end
863
- require 'rubygems'
864
887
  @gemdir = Pathname.new(Gem.dir) + gempath
865
888
  else
866
889
  parse = lambda do |path|
867
890
  next unless path
868
891
 
869
- lib = Regexp.new(['', 'gems', "#{project}-([^#{File::SEPARATOR}]+)", ''].join(File::SEPARATOR))
892
+ lib = Regexp.new(['', 'gems', "#{gemname}-([^#{File::SEPARATOR}]+)", ''].join(File::SEPARATOR))
870
893
  if (ver = path[lib, 1]) && (val = path[/\A(.+)#{gempath(ver[1])}/, 1])
871
894
  set.call(ver, val)
872
895
  end
873
896
  end
874
897
  if RUBY_VERSION >= '2.6'
875
898
  target = RUBY_VERSION.start_with?('2.6') ? RubyVM : $LOAD_PATH
876
- parse.call(target.resolve_feature_path(project)&.last)
899
+ parse.call(target.resolve_feature_path(gemname)&.last)
877
900
  end
878
- if !@gemdir && !pwd_set { parse.call(`#{bundle_output('show', project)}`) }
901
+ if !@gemdir && !pwd_set { parse.call(`#{bundle_output('show', gemname)}`) }
879
902
  raise_error 'gems directory not found'
880
903
  end
881
904
  end
@@ -958,9 +981,9 @@ module Squared
958
981
 
959
982
  def read_rakefile
960
983
  @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|
984
+ opt = rakepwd
985
+ pwd_set(pass: !opt.nil?) do
986
+ IO.popen(rake_output(opt, '-AT').to_s).each do |line|
964
987
  next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
965
988
 
966
989
  ret << [$1, $2]
@@ -982,26 +1005,44 @@ module Squared
982
1005
  end
983
1006
 
984
1007
  def rakefile
985
- return @rakefile if @rakefile
1008
+ return @rakefile unless @rakefile.nil?
986
1009
 
987
1010
  file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }
988
- @rakefile = file ? path + file : ''
1011
+ @rakefile = file ? path + file : false
989
1012
  end
990
1013
 
991
1014
  def rakepwd
992
- return if pwd? || Rake::VERSION < '13.0.4'
1015
+ return unless !pwd? && semgte?(Rake::VERSION, '13.0.4')
993
1016
 
994
1017
  quote_option 'C', path
995
1018
  end
996
1019
 
997
1020
  def gempwd
998
- return if pwd? || Gem::VERSION < '3.4.2'
1021
+ return unless !pwd? && semgte?(Gem::VERSION, '3.4.2')
999
1022
 
1000
1023
  quote_option 'C', path
1001
1024
  end
1002
1025
 
1003
- def gempath(val = @version)
1004
- File.join('gems', "#{project}-#{val}")
1026
+ def gemfile
1027
+ return @gemfile unless @gemfile.nil?
1028
+
1029
+ @gemfile = [project, name].map! { |val| path + "#{val}.gemspec" }
1030
+ .concat(path.glob('*.gemspec'))
1031
+ .find { |file| File.exist?(file) } || false
1032
+ end
1033
+
1034
+ def gemlib
1035
+ @gemlib ||= begin
1036
+ lib = Set.new(['lib'])
1037
+ if (spec = gemspec)
1038
+ lib.merge(spec.require_paths || [])
1039
+ end
1040
+ lib.select { |file| basepath(file).exist? }
1041
+ end
1042
+ end
1043
+
1044
+ def gempath(val = version)
1045
+ File.join('gems', "#{gemname}-#{val}")
1005
1046
  end
1006
1047
  end
1007
1048
 
@@ -35,9 +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')
39
-
40
- raise_error 'user cancelled'
38
+ exit 1 unless pass || confirm("Run? [#{sub_style(target, styles: styles)}] [y/N] ", 'N')
41
39
  end
42
40
 
43
41
  def strip(val)
@@ -47,6 +45,15 @@ module Squared
47
45
  val.map { |s| s.sub(/\A-([a-z\d])(.+)\z/i, '\1=\2').sub(/\A--?/, '') }.reject(&:empty?)
48
46
  end
49
47
 
48
+ def select(list, bare: true, no: true, single: false, double: false)
49
+ ret = bare ? list.grep_v(/=/) : list.grep(/=/).map! { |val| val.split('=', 2).first }
50
+ ret.map! { |val| val.split('|', 2).last }
51
+ ret = ret.grep_v(/^no-/) unless no
52
+ return ret if single == double
53
+
54
+ ret.select { |val| single ? val.size == 1 : val.size > 1 }
55
+ end
56
+
50
57
  def arg?(target, *args, value: false, **)
51
58
  r, s = args.partition { |val| val.is_a?(Regexp) }
52
59
  unless s.empty?
@@ -55,14 +62,21 @@ module Squared
55
62
  end
56
63
  target.any? { |opt| r.any? { |val| opt&.match?(val) } }
57
64
  end
65
+
66
+ def pattern?(val)
67
+ val.match?(/(?:\A\^|\$\z)/) || val.match?(/(?:\.[*+]|\(\?:|\\[dsw]|\[.+\]|\{\d+,?\d*\})/)
68
+ end
58
69
  end
59
70
 
60
71
  attr_reader :target, :extras, :found, :errors, :values, :project, :path
61
72
 
62
73
  def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
63
- :merge, :delete, :delete?, :delete_if, :grep, :inspect, :to_a, :to_s
74
+ :merge, :delete, :delete?, :delete_if, :grep, :grep_v, :inspect, :to_a, :to_s
64
75
  def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :last, :shift, :unshift,
65
- :pop, :push, :join, :map, :map!, :select, :reject, :size
76
+ :pop, :push, :index, :delete_at, :join, :map, :map!, :select, :reject, :size
77
+
78
+ def_delegator :@extras, :delete, :remove
79
+ def_delegator :@extras, :delete_if, :remove_if
66
80
 
67
81
  def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
68
82
  @target = target.is_a?(Set) ? target : Set.new(target)
@@ -140,35 +154,35 @@ module Squared
140
154
  skip = false
141
155
  opts.each do |opt|
142
156
  next skip = true if opt == '--'
143
- next @extras << opt if skip
157
+ next push opt if skip
144
158
 
145
159
  if single&.match?(opt)
146
- target << "-#{opt}"
160
+ add "-#{opt}"
147
161
  elsif bare.include?(opt)
148
- target << (opt.size == 1 ? "-#{opt}" : "--#{opt}")
162
+ add(opt.size == 1 ? "-#{opt}" : "--#{opt}")
149
163
  elsif opt.start_with?('no-') && no.include?(name = opt[3..-1])
150
- target << "--no-#{name}"
164
+ add "--no-#{name}"
151
165
  else
152
166
  if opt =~ /\A([^=]+)=(.+)\z/
153
167
  key = $1
154
168
  val = $2
155
169
  merge = m.include?(key)
156
170
  if e.include?(key)
157
- target << shell_option(key, val, merge: merge)
171
+ add shell_option(key, val, merge: merge)
158
172
  elsif q.include?(key)
159
- target << quote_option(key, val, double: qq.include?(key), merge: merge)
173
+ add quote_option(key, val, double: qq.include?(key), merge: merge)
160
174
  elsif p.include?(key) && path
161
- target << quote_option(key, path + val, merge: merge)
175
+ add quote_option(key, path + val, merge: merge)
162
176
  elsif b.include?(key) || numcheck.call(key, val)
163
- target << basic_option(key, val, merge: merge)
177
+ add basic_option(key, val, merge: merge)
164
178
  elsif merge
165
- target << basic_option(key, val, merge: true)
179
+ add basic_option(key, val, merge: true)
166
180
  else
167
- @extras << opt
181
+ push opt
168
182
  end
169
183
  opt = key
170
184
  else
171
- @extras << opt
185
+ push opt
172
186
  skip = true if args
173
187
  end
174
188
  skip = true if first&.any? { |s| s.is_a?(Regexp) ? opt.match?(s) : !opt.include?(s) }
@@ -231,7 +245,42 @@ module Squared
231
245
  args = items[0...i] + args + items[i..-1]
232
246
  target.clear
233
247
  end
234
- merge(args)
248
+ merge args
249
+ self
250
+ end
251
+
252
+ def add_path(*args, **kwargs)
253
+ add shell_quote(path ? path.join(*args) : File.join(*args), **kwargs)
254
+ self
255
+ end
256
+
257
+ def add_quote(*args, **kwargs)
258
+ merge(args.map { |val| shell_quote(val, **kwargs) })
259
+ self
260
+ end
261
+
262
+ def splice(*exclude, quote: true, delim: true, path: false, pattern: false, &blk)
263
+ found, other = if block_given?
264
+ partition(&blk)
265
+ elsif exclude.first.is_a?(Symbol)
266
+ partition(&exclude.first)
267
+ else
268
+ partition do |val|
269
+ next false if pattern && OptionPartition.pattern?(val)
270
+
271
+ exclude.none? { |pat| val.match?(Regexp.new(pat)) }
272
+ end
273
+ end
274
+ unless found.empty?
275
+ add '--' if delim
276
+ extras.clear
277
+ extras.concat(other)
278
+ if path
279
+ found.each { |val| add_path(val) }
280
+ else
281
+ merge(quote ? found.map! { |val| shell_quote(val) } : found)
282
+ end
283
+ end
235
284
  self
236
285
  end
237
286
 
@@ -113,35 +113,17 @@ module Squared
113
113
  def __repo__(**kwargs)
114
114
  kwargs.delete(:parallel) if env('REPO_SYNC', ignore: '0')
115
115
 
116
- namespace(name = task_name('repo')) do |repo|
116
+ namespace(task_name('repo')) do |ns|
117
+ path = ns.scope.path
117
118
  branch = env('REPO_MANIFEST') || Repo.read_manifest(root)
118
119
  target = branch || manifest
120
+ cmd = nil
119
121
  stage = nil
120
- failfast = true
121
- cmd = []
122
122
  newline = ARGV.index { |val| val.start_with?('repo:') }.to_i > 0
123
- parse_opts = lambda do |args|
124
- args.to_a.each do |val|
125
- case val
126
- when 'no-fail'
127
- failfast = false
128
- when 'force'
129
- cmd << '--force-checkout'
130
- when 'rebase'
131
- cmd << '--rebase'
132
- when 'detach'
133
- cmd << '--detach'
134
- when 'gc'
135
- cmd << '--auto-gc'
136
- when 'no-update'
137
- cmd << '--no-manifest-update'
138
- end
139
- end
140
- end
141
123
  desc = lambda do |val, alt = nil|
142
124
  if (ver = branch || alt)
143
- val = val.sub('{0}', 'opts*=force,rebase,detach,gc,no-update,no-fail')
144
- task_desc(task_name('repo'), val, ver)
125
+ val = val.sub('{0}', 'opts*=force,rebase,detach,fail,no-update,gc')
126
+ task_desc(path, val, ver)
145
127
  else
146
128
  task_desc 'inactive'
147
129
  end
@@ -149,20 +131,22 @@ module Squared
149
131
 
150
132
  desc.call('all[{0}]')
151
133
  task 'all', [:opts] do |_, args|
152
- parse_opts.call(args)
134
+ cmd ||= repo_opts args
153
135
  stage ||= 'all'
154
- repo['sync'].invoke
155
- next if env('REPO_DRYRUN', equals: '2')
136
+ ns['sync'].invoke
137
+ next if env('REPO_STAGE', equals: '1')
156
138
 
157
139
  @project.select do |_, proj|
158
140
  next unless proj.enabled?(proj.workspace.baseref)
159
141
 
160
142
  proj.depend(sync: true) if proj.depend?
161
- proj.build? unless env('REPO_DRYRUN', ignore: '0')
143
+ next if env('REPO_STAGE', equals: '2')
144
+
145
+ proj.build?
162
146
  end
163
147
  .each_value do |proj|
164
148
  proj.build(sync: true)
165
- next unless proj.dev? && proj.copy?
149
+ next unless proj.dev? && proj.copy? && !env('REPO_STAGE', equals: '3')
166
150
 
167
151
  if (ws = proj.workspace).task_defined?(target = task_join(proj.name, 'copy'))
168
152
  task_invoke(target, **ws.invokeargs)
@@ -174,38 +158,37 @@ module Squared
174
158
 
175
159
  desc.call("init[manifest?=#{target},{0}]", target)
176
160
  task 'init', [:manifest, :opts] do |_, args|
177
- parse_opts.call(args)
161
+ cmd = repo_opts args
178
162
  stage = 'init'
179
163
  puts if newline
180
164
  Common::System.shell("repo init -u #{env('REPO_URL') || manifest_url} -m #{args.manifest || target}.xml",
181
165
  chdir: root)
182
- repo['all'].invoke
166
+ next if env('REPO_STAGE', equals: '0')
167
+
168
+ ns['all'].invoke
183
169
  end
184
170
 
185
171
  desc.call('sync[{0}]')
186
- task 'sync', [:opts] do |_, args|
187
- unless branch || stage == 'init'
188
- raise_error('repo not initialized', hint: task_name('repo:init'), kind: LoadError)
189
- end
190
- parse_opts.call(args)
172
+ task 'sync', [:opts] do |t, args|
173
+ raise_error 'repo not initialized' unless branch || stage == 'init'
174
+ cmd ||= repo_opts args
191
175
  cmd << "-j#{ENV.fetch('REPO_JOBS', Rake::CpuCounter.count)}"
192
- cmd << '--fail-fast' if failfast
193
- puts if newline && stage != 'init'
176
+ puts unless !newline || stage == 'init'
194
177
  begin
195
- Common::System.shell("repo sync #{cmd.join(' ')}", chdir: root, exception: failfast)
178
+ Common::System.shell("repo sync #{cmd.join(' ')}", chdir: root, exception: cmd.include?('--fail-fast'))
196
179
  rescue Errno::ENOENT => e
197
180
  emphasize(e, title: root)
198
181
  raise
199
182
  rescue StandardError => e
200
- emphasize(e, title: "rake stash #{task_name(task_join('repo', stage || 'sync'))}")
183
+ emphasize(e, title: "rake stash #{t.name}")
201
184
  raise
202
185
  end
203
186
  end
204
187
 
205
188
  series.sync.push(
206
- task_join(name, 'all'),
207
- task_join(name, 'init'),
208
- task_join(name, 'sync')
189
+ task_join(path, 'all'),
190
+ task_join(path, 'init'),
191
+ task_join(path, 'sync')
209
192
  )
210
193
  end
211
194
  end
@@ -221,6 +204,27 @@ module Squared
221
204
  )
222
205
  end
223
206
 
207
+ def repo_opts(args)
208
+ ret = []
209
+ args.to_a.each do |val|
210
+ case val
211
+ when 'force'
212
+ ret << '--force-checkout'
213
+ when 'rebase'
214
+ ret << '--rebase'
215
+ when 'detach'
216
+ ret << '--detach'
217
+ when 'fail'
218
+ ret << '--fail-fast'
219
+ when 'no-update'
220
+ ret << '--no-manifest-update'
221
+ when 'gc'
222
+ ret << '--auto-gc'
223
+ end
224
+ end
225
+ ret
226
+ end
227
+
224
228
  def repo?
225
229
  !manifest_url.nil? && (repo_install? || @repo_override == true)
226
230
  end
@@ -10,9 +10,9 @@ module Squared
10
10
 
11
11
  TASK_BASE = []
12
12
  TASK_BATCH = {}
13
- TASK_EXTEND = Workspace.hashlist
13
+ TASK_EXTEND = Support.hashlist
14
14
  TASK_KEYS = []
15
- TASK_ALIAS = Workspace.hashobj
15
+ TASK_ALIAS = Support.hashobj
16
16
  TASK_NAME = {}
17
17
  private_constant :TASK_BASE, :TASK_BATCH, :TASK_EXTEND, :TASK_KEYS, :TASK_ALIAS, :TASK_NAME
18
18
 
@@ -79,8 +79,8 @@ module Squared
79
79
  @chain = {}
80
80
  @exclude = exclude.freeze
81
81
  @session = {
82
- group: Workspace.hashlist,
83
- parent: Workspace.hashlist,
82
+ group: Support.hashlist,
83
+ parent: Support.hashlist,
84
84
  id: []
85
85
  }
86
86
  @data = {}
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Squared
4
+ module Workspace
5
+ module Support
6
+ class << self
7
+ def hashobj
8
+ Hash.new { |data, key| data[key] = {} }
9
+ end
10
+
11
+ def hashlist
12
+ Hash.new { |data, key| data[key] = [] }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'support/base'
3
4
  require_relative 'support/data'