squared 0.4.13 → 0.5.0

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.
@@ -102,6 +102,7 @@ module Squared
102
102
  end
103
103
  dependfile_set GEMFILE
104
104
  @autodetect = autodetect
105
+ @rakelist = nil
105
106
  return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || (file = rakefile).nil?
106
107
 
107
108
  begin
@@ -222,7 +223,7 @@ module Squared
222
223
  args = args.to_a.drop(1)
223
224
  unless file && !file.include?('*')
224
225
  values = ['Arguments']
225
- values.unshift('Options') unless file
226
+ values.prepend('Options') unless file
226
227
  file, opts, extra = choice_index('Select a file', Dir.glob(file || '*.rb', base: path),
227
228
  values: values, force: true, series: !args.include?('v'))
228
229
  if file
@@ -310,7 +311,7 @@ module Squared
310
311
  end
311
312
  log.info cmd.to_s
312
313
  on :first, :outdated
313
- banner = format_banner(cmd.to_s)
314
+ banner = format_banner cmd.to_s
314
315
  print_item banner if sync
315
316
  pwd_set(from: :outdated) do
316
317
  start = 0
@@ -401,7 +402,7 @@ module Squared
401
402
  end
402
403
  if found > 0
403
404
  begin
404
- if major == 0 && dependfile.read =~ /\b(?:source\s+(["'])(.+?)\1|remote:\s+(\S+))/
405
+ if major == 0 && dependfile.read =~ /\b(?:source\s+(["'])((?~\1))\1|remote:\s+(\S+))/
405
406
  status = ($2 || $3).chomp('/')
406
407
  right = true
407
408
  end
@@ -427,7 +428,7 @@ module Squared
427
428
  def update(flag, opts = [])
428
429
  bundle_session 'update', "--#{flag}"
429
430
  append_bundle(opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common],
430
- append: flag == :all ? nil : /\A\w+=/)
431
+ append: flag == :all ? nil : /\A[a-z\-]+=/)
431
432
  run_rb(from: :update)
432
433
  end
433
434
 
@@ -436,7 +437,7 @@ module Squared
436
437
  when :file, :script
437
438
  op = OptionPartition.new(opts, OPT_RUBY[:ruby], ruby_session, project: self, args: true)
438
439
  if file
439
- op.extras.unshift(shell_quote(path + file))
440
+ op.extras.prepend(shell_quote(path + file))
440
441
  elsif command
441
442
  op << quote_option('e', command, option: false)
442
443
  end
@@ -463,8 +464,9 @@ module Squared
463
464
  when 'rvm'
464
465
  `rvm current`[/^\S+/, 0]
465
466
  when 'rbenv'
466
- name = `rbenv version-name`
467
- name =~ SEM_VER ? "ruby #{name}" : name
467
+ `rbenv version-name`.yield_self do |name|
468
+ name.match?(SEM_VER) ? "ruby #{name}" : name
469
+ end
468
470
  when 'chruby.sh'
469
471
  chruby = session_output 'source', val
470
472
  `#{chruby.with('ruby --version')}`
@@ -480,7 +482,7 @@ module Squared
480
482
  when 'chruby.sh'
481
483
  `#{chruby.with('chruby --version')}`.sub(':', '')
482
484
  when 'install'
483
- "asdf #{`asdf version`.sub(/^v/, '')}"
485
+ "asdf #{`asdf version`.delete_prefix('v')}"
484
486
  else
485
487
  `#{cmd} --version`
486
488
  end)
@@ -639,8 +641,7 @@ module Squared
639
641
  styles = %i[yellow]
640
642
  pat = pat.last
641
643
  end
642
- b = b.rjust(e)
643
- b = sub_style(b, *colormap(styles), pat: pat, index: 2)
644
+ b = sub_style(b.rjust(e), *colormap(styles), pat: pat, index: 2)
644
645
  h = sub_style(c.rjust(f), styles: latest.flatten.compact, pat: pat, index: 2)
645
646
  j += 1
646
647
  if queue
@@ -658,15 +659,15 @@ module Squared
658
659
  else
659
660
  unless update.empty?
660
661
  cmd = gem_output 'update', '-f'
661
- if (val = option('document', prefix: 'gem', ignore: false))
662
+ option('document', prefix: 'gem', ignore: false) do |val|
662
663
  cmd << case val
663
664
  when '0', 'false'
664
665
  '--no-document'
665
666
  else
666
- basic_option('document', val)
667
+ basic_option 'document', val
667
668
  end
668
669
  end
669
- if (val = option('user-install', prefix: 'gem', ignore: false))
670
+ option('user-install', prefix: 'gem', ignore: false) do |val|
670
671
  cmd << case val
671
672
  when '0', 'false'
672
673
  '--no-user-install'
@@ -679,8 +680,13 @@ module Squared
679
680
  end
680
681
  unless stdin?
681
682
  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)
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
684
690
  puts status
685
691
  end
686
692
  end
@@ -694,7 +700,7 @@ module Squared
694
700
  raise_error("unknown args: #{op.join(', ')}", hint: flag)
695
701
  end
696
702
  elsif flag == :build
697
- spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *Dir.glob(path + '*.gemspec')]
703
+ spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *path.glob('*.gemspec')]
698
704
  op << File.basename(spec) if (spec = spec.find { |file| File.exist?(file) })
699
705
  end
700
706
  when :exec
@@ -767,7 +773,7 @@ module Squared
767
773
  def irb(name, opts = [], path: @path + 'lib', load: nil)
768
774
  op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
769
775
  r = as_a name
770
- r.unshift('bundler/setup') unless load
776
+ r.prepend('bundler/setup') unless load
771
777
  r.each { |val| op << shell_option('r', val, merge: true) }
772
778
  as_a(path).each { |val| op << quote_option('I', val, merge: true) }
773
779
  if load
@@ -821,14 +827,15 @@ module Squared
821
827
  pwd_set(pass: !pwd.nil?) do
822
828
  out = `#{gem_output(pwd, 'list --local -d', project)}`
823
829
  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
830
+ $1.split(/\s*,\s*/)
831
+ .prepend(@version)
832
+ .uniq
833
+ .each do |val|
834
+ next unless out =~ /\(#{Regexp.escape(val)}(?:,[^)]+|\b)\):([^\n]+)/
835
+
836
+ set.call(val, $1)
837
+ break
838
+ end
832
839
  end
833
840
  end
834
841
  end
@@ -31,7 +31,7 @@ module Squared
31
31
  def clear(target, opts, pass: true, styles: nil, **kwargs)
32
32
  return if opts.empty?
33
33
 
34
- kwargs[:subject] ||= stripext(target.first)
34
+ kwargs[:subject] ||= stripext target.first
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)
@@ -50,10 +50,11 @@ module Squared
50
50
  def arg?(target, *args, value: false, **)
51
51
  r, s = args.partition { |val| val.is_a?(Regexp) }
52
52
  unless s.empty?
53
- s.map! { |val| Regexp.escape(shell_option(val)) }
53
+ s.map! { |val| Regexp.escape(val.start_with?('-') ? val : shell_option(val)) }
54
54
  r << /\A(?:#{s.join('|')})#{value ? '[ =].' : '(?: |=|\z)'}/
55
55
  end
56
- target.any? { |opt| r.any? { |val| opt&.match?(val) } }
56
+ s = target.to_a.compact
57
+ r.any? { |pat| s.any?(pat) }
57
58
  end
58
59
  end
59
60
 
@@ -65,7 +66,7 @@ module Squared
65
66
  :pop, :push, :join, :map, :map!, :select, :reject, :size
66
67
 
67
68
  def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
68
- @target = target.is_a?(Set) ? target : Set.new(target)
69
+ @target = target.is_a?(Set) ? target : target.to_set
69
70
  @project = project
70
71
  @path = path || project&.path
71
72
  @errors = []
@@ -209,6 +210,80 @@ module Squared
209
210
  OptionPartition.arg?(target, *args, **kwargs)
210
211
  end
211
212
  end
213
+
214
+ class JoinSet < Set
215
+ def self.to_s
216
+ super[/[^:]+\z/, 0]
217
+ end
218
+
219
+ attr_reader :delim
220
+
221
+ def initialize(data = [], delim: ' ')
222
+ super(data.compact)
223
+ @delim = delim
224
+ end
225
+
226
+ def last(val, pat)
227
+ (@last ||= []).append([val, pat, $1]) if val =~ pat
228
+ self << val
229
+ end
230
+
231
+ def pass(&blk)
232
+ ret = to_a.map!(&:to_s).reject(&:empty?)
233
+ @last&.each do |val, pat, key|
234
+ i = []
235
+ j = nil
236
+ ret.each_with_index do |opt, index|
237
+ if opt == val
238
+ j = index
239
+ elsif j && opt[pat, 1] == key
240
+ i << index
241
+ end
242
+ end
243
+ next unless j && !i.empty?
244
+
245
+ val = ret[j]
246
+ cur = j
247
+ i.each do |k|
248
+ ret[cur] = ret[k]
249
+ cur = k
250
+ end
251
+ ret[i.last] = val
252
+ end
253
+ block_given? ? ret.reject(&blk) : ret
254
+ end
255
+
256
+ def and(*args)
257
+ self << '&&'
258
+ merge args
259
+ end
260
+
261
+ def or(*args)
262
+ self << '||'
263
+ merge args
264
+ end
265
+
266
+ def with(*args, &blk)
267
+ temp('&&', *args, &blk)
268
+ end
269
+
270
+ def temp(*args, &blk)
271
+ args.compact!
272
+ ret = pass(&blk)
273
+ ret = Set.new(ret.concat(args)).to_a unless args.empty?
274
+ ret.join(@delim)
275
+ end
276
+
277
+ def done
278
+ ret = to_s
279
+ clear
280
+ ret
281
+ end
282
+
283
+ def to_s
284
+ pass.join(@delim)
285
+ end
286
+ end
212
287
  end
213
288
  end
214
289
  end
@@ -3,16 +3,6 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  module Project
6
- class << self
7
- attr_accessor :line_width
8
-
9
- def max_width(lines)
10
- n = [lines.max_by(&:size).size, 80].max
11
- [n, Rake.application.terminal_width].min
12
- end
13
- end
14
-
15
- @line_width = ENV.fetch('LOG_COLUMNS', 80).to_i
16
6
  end
17
7
  end
18
8
  end
@@ -57,10 +57,10 @@ module Squared
57
57
  when 'verbose'
58
58
  @verbose = 1
59
59
  if script.is_a?(Array)
60
- script[0] = task_join(script[0], 'verbose')
60
+ script[0] = task_join script[0], 'verbose'
61
61
  script
62
62
  else
63
- task_join(script, 'verbose')
63
+ task_join script, 'verbose'
64
64
  end
65
65
  when 'silent'
66
66
  @verbose = false
@@ -81,8 +81,8 @@ module Squared
81
81
  data[:run] = run
82
82
  end
83
83
  data[:global] = true
84
- data[:dev] = env_match('REPO_DEV', dev)
85
- data[:prod] = env_match('REPO_PROD', prod)
84
+ data[:dev] = env_match 'REPO_DEV', dev
85
+ data[:prod] = env_match 'REPO_PROD', prod
86
86
  if (val = env('REPO_GROUP'))
87
87
  script_set(data, group: val.split(','))
88
88
  found = true
@@ -201,7 +201,7 @@ module Squared
201
201
  end
202
202
  end
203
203
 
204
- series.sync.push(
204
+ series.sync.append(
205
205
  task_join(name, 'all'),
206
206
  task_join(name, 'init'),
207
207
  task_join(name, 'sync')
@@ -68,7 +68,7 @@ module Squared
68
68
 
69
69
  attr_reader :sync, :multiple, :parallel
70
70
 
71
- def_delegators :@data, :[], :each, :each_key, :keys, :fetch, :to_a, :to_s, :inspect, :merge!, :key?
71
+ def_delegators :@data, :[], :each, :each_key, :keys, :key?, :fetch, :update, :merge!, :to_a, :to_s, :inspect
72
72
  def_delegators :@workspace, :task_desc, :task_name, :task_namespace, :task_join, :format_desc
73
73
 
74
74
  def initialize(workspace, exclude: [])
@@ -112,29 +112,29 @@ module Squared
112
112
 
113
113
  def build(parallel: [], pattern: [], **)
114
114
  subcheck = ->(val) { (ns = task_namespace(val)) && parallel.include?(ns) }
115
- @data.merge!(@session[:parent]) if @session[:id].uniq.size > 1
116
- @data.merge!(@session[:group])
115
+ @data.update(@session[:parent]) if @session[:id].uniq.size > 1
116
+ @data.update(@session[:group])
117
117
  @data.each do |key, items|
118
118
  next if exclude?(key, true) || @workspace.task_exclude?(t = name_get(key))
119
119
 
120
120
  key = task_name t
121
- val = format_desc(key, out: true)
121
+ title = format_desc(key, out: true)
122
122
  if items.size > 1
123
123
  @multiple << key
124
124
  if parallel.include?(t) || pattern.any? { |pat| t.match?(pat) } || subcheck.call(t)
125
- task_desc("#{val} (thread)", name: key)
125
+ task_desc("#{title} (thread)", name: key) if title
126
126
  multitask key => items
127
127
  @parallel << key
128
128
 
129
- s = task_join(key, 'sync')
130
- task_desc("#{val} (sync)", name: s)
129
+ s = task_join key, 'sync'
130
+ task_desc("#{title} (sync)", name: s) if title
131
131
  task s => items
132
132
  @sync << s
133
133
  next
134
134
  end
135
135
  end
136
136
 
137
- task_desc(val, name: key)
137
+ task_desc(title, name: key) if title
138
138
  task key => items
139
139
  end
140
140
  @multiple.concat(sync)
@@ -5,6 +5,7 @@ module Squared
5
5
  module Support
6
6
  RunData = Struct.new(:run, :block)
7
7
  ChainData = Struct.new(:action, :step, :with, :before, :after, :sync)
8
+ BannerData = Struct.new(:command, :order, :styles, :border)
8
9
  end
9
10
  end
10
11
  end
@@ -10,7 +10,7 @@ module Squared
10
10
  if id.is_a?(Symbol)
11
11
  project id
12
12
  else
13
- __get__(:project).find { |_, val| File.expand_path(val.path) == File.expand_path(id) }
13
+ __get__(:project).find { |_, val| File.expand_path(val.path) == File.expand_path(id, __dir__) }
14
14
  end
15
15
  end
16
16
  ret.size == 1 ? ret.first : ret
data/squared.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = %q{Rake task generator for managing multi-language workspaces.}
12
12
  spec.description = %q{Rake task generator for managing multi-language workspaces.}
13
13
  spec.homepage = "https://github.com/anpham6/squared"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
15
15
  spec.licenses = ["BSD-3-Clause"]
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
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.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -80,7 +80,6 @@ files:
80
80
  - lib/squared/app.rb
81
81
  - lib/squared/common.rb
82
82
  - lib/squared/common/base.rb
83
- - lib/squared/common/class.rb
84
83
  - lib/squared/common/format.rb
85
84
  - lib/squared/common/prompt.rb
86
85
  - lib/squared/common/shell.rb
@@ -118,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
117
  requirements:
119
118
  - - ">="
120
119
  - !ruby/object:Gem::Version
121
- version: 2.4.0
120
+ version: 2.5.0
122
121
  required_rubygems_version: !ruby/object:Gem::Requirement
123
122
  requirements:
124
123
  - - ">="
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'set'
4
- require 'forwardable'
5
-
6
- module Squared
7
- module Common
8
- class SymSet
9
- extend Forwardable
10
-
11
- def self.to_s
12
- super[/[^:]+\z/, 0]
13
- end
14
-
15
- def_delegators :@data, :+, :each, :each_with_index, :entries, :merge, :include?
16
-
17
- def initialize(data = [])
18
- @data = Set.new(data)
19
- end
20
-
21
- def add(val)
22
- @data.add(val.to_sym)
23
- end
24
-
25
- def to_a
26
- @data.to_a.freeze
27
- end
28
-
29
- def to_s
30
- @data.to_s.sub('Set', SymSet.to_s)
31
- end
32
-
33
- alias inspect to_s
34
- end
35
-
36
- class JoinSet < Set
37
- def self.to_s
38
- super[/[^:]+\z/, 0]
39
- end
40
-
41
- attr_reader :delim
42
-
43
- def initialize(data = [], delim: ' ')
44
- super(data.compact)
45
- @delim = delim
46
- end
47
-
48
- def last(val, pat)
49
- (@last ||= []).push([val, pat, $1]) if val =~ pat
50
- self << val
51
- end
52
-
53
- def pass(&blk)
54
- ret = to_a.map!(&:to_s).reject(&:empty?)
55
- @last&.each do |val, pat, key|
56
- i = []
57
- j = nil
58
- ret.each_with_index do |opt, index|
59
- if opt == val
60
- j = index
61
- elsif j && opt[pat, 1] == key
62
- i << index
63
- end
64
- end
65
- next unless j && !i.empty?
66
-
67
- val = ret[j]
68
- cur = j
69
- i.each do |k|
70
- ret[cur] = ret[k]
71
- cur = k
72
- end
73
- ret[i.last] = val
74
- end
75
- block_given? ? ret.reject(&blk) : ret
76
- end
77
-
78
- def and(*args)
79
- self << '&&'
80
- merge(args)
81
- end
82
-
83
- def or(*args)
84
- self << '||'
85
- merge(args)
86
- end
87
-
88
- def with(*args, &blk)
89
- temp('&&', *args, &blk)
90
- end
91
-
92
- def temp(*args, &blk)
93
- args.compact!
94
- ret = pass(&blk)
95
- ret = Set.new(ret.concat(args)).to_a unless args.empty?
96
- ret.join(@delim)
97
- end
98
-
99
- def done
100
- ret = to_s
101
- clear
102
- ret
103
- end
104
-
105
- def to_s
106
- pass.join(@delim)
107
- end
108
- end
109
- end
110
- end