squared 0.5.15 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb26d6cf2dfdece4362de8ae2e5748eb11cc05e4158d4d81a43c1c63320764b4
4
- data.tar.gz: 2d01a9695d8953acd20d568be48089424bc1afc23039f372d1125a77562792bd
3
+ metadata.gz: 91dfb7530ecdb1ab70461ab8bbbf894e706ea6f78b5e9ada99c930d0819e9ec9
4
+ data.tar.gz: 82591aa893baf80057a3193e95763b8ce98c13593de54dffd00e31f0c27a3bf8
5
5
  SHA512:
6
- metadata.gz: c3f191d7014c93cb20c6ace155e9b3e56561e8d88ad48f67793da484d73b50e7d7fa183ba7f52dfdfc7d434c1acedd1a748d4e95b8726763235fd5e45df893d7
7
- data.tar.gz: f7ce5072078a05a56c850420f17b3923444b8581e7bd06a71d61a13197ac91b05d883edad0774b890c28edd79bd8da597e0accac53559f8bd1da152890d708f9
6
+ metadata.gz: ce78218f60162cda536062dc37e5f27f30b5cd25e1afcac502c3519085988594c01ea149b47ecd536373ba2f4312162d468915fd6792f27f15d1d301bf2e03eb
7
+ data.tar.gz: b0b6cec02ec4c531ddbabfa4ff1f3f8a87cf4592dd48fd86b74a8ac3787c602df165b0526cd69af8c585c221dcace1bcfc606a1bc511e3722f1e1b9cd1161e17
data/CHANGELOG.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.17] - 2025-11-22
4
+
5
+ ### Fixed
6
+
7
+ - See `0.4.31`.
8
+
9
+ ## [0.4.31] - 2025-11-22
10
+
11
+ ### Changed
12
+
13
+ - Project base attribute project was converted into an accessor.
14
+ - Ruby command flag is given precedence to a program file.
15
+
16
+ ### Fixed
17
+
18
+ - Repo application tasks are not created on Windows.
19
+ - Repo module used conflicting REPO_URL with Repo application.
20
+ - Project task outdated did not check pass and only exclusions.
21
+ - Workspace static method resolve did nothing when given a String.
22
+ - Project base run command types did not include Struct.
23
+ - Project change directory context did not always restore when raised.
24
+ - Ruby file method attributes did not always return nil.
25
+ - JoinSet with a delimiter did not report correct size.
26
+
27
+ ## [0.5.16] - 2025-11-14
28
+
29
+ ### Fixed
30
+
31
+ - See `0.4.30`.
32
+
33
+ ## [0.4.30] - 2025-11-14
34
+
35
+ ### Added
36
+
37
+ - Config viewer can read items by index in an Array.
38
+
39
+ ### Fixed
40
+
41
+ - Node command add uses event name "add" and not "depend".
42
+ - Node command add did not include packages with Yarn and PNPM.
43
+ - Git method revbuild did not splat build arguments.
44
+
3
45
  ## [0.5.15] - 2025-11-08
4
46
 
5
47
  ### Fixed
@@ -1229,6 +1271,8 @@
1229
1271
 
1230
1272
  - Changelog was created.
1231
1273
 
1274
+ [0.5.17]: https://github.com/anpham6/squared-ruby/releases/tag/v0.5.17
1275
+ [0.5.16]: https://github.com/anpham6/squared-ruby/releases/tag/v0.5.16
1232
1276
  [0.5.15]: https://github.com/anpham6/squared-ruby/releases/tag/v0.5.15
1233
1277
  [0.5.14]: https://github.com/anpham6/squared-ruby/releases/tag/v0.5.14
1234
1278
  [0.5.13]: https://github.com/anpham6/squared-ruby/releases/tag/v0.5.13
@@ -1245,6 +1289,8 @@
1245
1289
  [0.5.2]: https://github.com/anpham6/squared-ruby/releases/tag/v0.5.2-ruby
1246
1290
  [0.5.1]: https://github.com/anpham6/squared-ruby/releases/tag/v0.5.1-ruby
1247
1291
  [0.5.0]: https://github.com/anpham6/squared-ruby/releases/tag/v0.5.0-ruby
1292
+ [0.4.31]: https://github.com/anpham6/squared-ruby/releases/tag/v0.4.31
1293
+ [0.4.30]: https://github.com/anpham6/squared-ruby/releases/tag/v0.4.30
1248
1294
  [0.4.29]: https://github.com/anpham6/squared-ruby/releases/tag/v0.4.29
1249
1295
  [0.4.28]: https://github.com/anpham6/squared-ruby/releases/tag/v0.4.28
1250
1296
  [0.4.27]: https://github.com/anpham6/squared-ruby/releases/tag/v0.4.27
data/README.md CHANGED
@@ -23,23 +23,9 @@ The range chart indicates the latest Ruby tested against at the time of release.
23
23
  gem install squared
24
24
  ```
25
25
 
26
- ### Optional
27
-
28
- * [Repo](https://source.android.com/docs/setup/reference/repo)
29
- * https://github.com/anpham6/squared-repo
30
- * Python 3.6
31
- * Not compatible with Windows
32
-
33
- ```sh
34
- mkdir -p ~/.bin
35
- PATH="${HOME}/.bin:${PATH}"
36
- curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
37
- chmod a+rx ~/.bin/repo
38
- ```
39
-
40
26
  ## Example - Rakefile
41
27
 
42
- Projects from any accessible folder can be added relative to the parent directory (e.g. *REPO_ROOT*) or absolutely. The same Rakefile can also manage other similarly cloned `Repo` repositories remotely by setting the `REPO_ROOT` environment variable to the location. Missing projects will simply be excluded from the task runner.
28
+ Projects from any accessible folder can be added relative to the parent directory or absolutely. Missing projects will simply be excluded from the task runner.
43
29
 
44
30
  ```ruby
45
31
  require "squared"
@@ -55,14 +41,6 @@ require "squared/app" # All workspace related mod
55
41
 
56
42
  # NODE_ENV = production
57
43
 
58
- # REPO_ROOT = /workspaces |
59
- # REPO_HOME = /workspaces/squared | Dir.pwd
60
- # rake = /workspaces/squared/Rakefile | main?
61
- # OR
62
- # REPO_ROOT = /workspaces | Dir.pwd
63
- # rake = /workspaces/Rakefile |
64
- # REPO_HOME = /workspaces/squared | main: "squared"
65
-
66
44
  # pathname = /workspaces/pathname
67
45
  # optparse = /workspaces/optparse
68
46
  # log = /workspaces/logger
@@ -77,7 +55,6 @@ require "squared/app" # All workspace related mod
77
55
  Workspace::Application
78
56
  .new(Dir.pwd, main: "squared") # Dir.pwd? (main? is implicitly basename)
79
57
  .banner("group", "project", styles: ["yellow", "black"], border: "bold") # name | project | path | ref | group? | parent? | version?
80
- .repo("https://github.com/anpham6/squared-repo", "nightly", script: ["build:dev", "build:prod"], ref: :node) # Repo (optional)
81
58
  .run("rake install", ref: :ruby)
82
59
  .depend(false, group: "default")
83
60
  .clean("rake clean", group: "default")
@@ -730,7 +707,37 @@ Workspace::Application
730
707
 
731
708
  ### Repo
732
709
 
733
- These global options also can target the application main suffix `${NAME}`. (e.g. REPO_ROOT_SQUARED)
710
+ * [Repo](https://source.android.com/docs/setup/reference/repo)
711
+ * https://github.com/anpham6/squared-repo
712
+ * Python 3.6
713
+ * Not compatible with Windows
714
+
715
+ ```sh
716
+ mkdir -p ~/.bin
717
+ PATH="${HOME}/.bin:${PATH}"
718
+ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
719
+ chmod a+rx ~/.bin/repo
720
+ ```
721
+
722
+ ```ruby
723
+ # REPO_ROOT = /workspaces |
724
+ # REPO_HOME = /workspaces/squared | Dir.pwd
725
+ # rake = /workspaces/squared/Rakefile | main?
726
+ #
727
+ # OR
728
+ #
729
+ # REPO_ROOT = /workspaces | Dir.pwd
730
+ # rake = /workspaces/Rakefile |
731
+ # REPO_HOME = /workspaces/squared | main: "squared"
732
+
733
+ Workspace::Application
734
+ .new(main: "squared")
735
+ .repo("https://github.com/anpham6/squared-repo", "nightly", script: ["build:dev", "prod"], ref: :node)
736
+ .add("squared", script: ["build:stage1", "build:stage2"])
737
+ .build
738
+ ```
739
+
740
+ These global options also can target the application main suffix `${NAME}`. (e.g. *REPO_ROOT_SQUARED*)
734
741
 
735
742
  ```sh
736
743
  REPO_ROOT # parent dir
@@ -742,7 +749,7 @@ REPO_DEV # pattern,0,1
742
749
  REPO_PROD # pattern,0,1
743
750
  REPO_WARN # 0,1
744
751
  REPO_SYNC # 0,1
745
- REPO_URL # manifest repository
752
+ REPO_GIT # manifest repository
746
753
  REPO_MANIFEST # e.g. latest,nightly,prod
747
754
  REPO_GROUPS # e.g. base,prod,docs
748
755
  REPO_STAGE # 0,1,2,3,4
@@ -750,6 +757,8 @@ REPO_SUBMODULLES # 0,1
750
757
  REPO_TIMEOUT # confirm dialog (seconds)
751
758
  ```
752
759
 
760
+ Other similarly cloned `Repo` repositories can be managed remotely by setting the `REPO_ROOT` environment variable to the location.
761
+
753
762
  ## LICENSE
754
763
 
755
764
  BSD 3-Clause
@@ -67,6 +67,7 @@ module Squared
67
67
  end
68
68
  wrap = ->(s, n) { "\x1B[#{n.join(';')}m#{s}\x1B[0m" }
69
69
  code = []
70
+ args.clear if args.size == 1 && args.first.nil?
70
71
  args.concat(Array(styles)).flatten.each_with_index do |type, i|
71
72
  next unless type
72
73
 
@@ -180,19 +181,20 @@ module Squared
180
181
  args = args.map(&:to_s)
181
182
  if level.is_a?(::Numeric)
182
183
  if append && respond_to?(:log)
183
- (log rescue nil).tap do |ref|
184
- ref.add(level, message(subject, *args, hint: hint, space: ', ')) if ref.is_a?(::Logger)
185
- end
184
+ ref = log rescue nil
185
+ ref.add(level, message(subject, *args, hint: hint, space: ', ')) if ref.is_a?(::Logger)
186
186
  end
187
- return false if !pass && level < ARG[:LEVEL]
187
+ return false unless pass || level >= ARG[:LEVEL]
188
188
  end
189
- if (args.size > 1 && !hint) || hint == false
189
+ if hint.nil? ? args.size > 1 : !hint
190
190
  title = log_title(level, color: false)
191
191
  sub = [pat: /\A(#{Regexp.escape(title)})(.*)\z/m, styles: __get__(:theme)[:logger][log_sym(level)]] if color
192
192
  emphasize(args, title: title + (subject ? " #{subject}" : ''), sub: sub, pipe: -1)
193
193
  else
194
194
  msg = [log_title(level, color: color)]
195
- msg << (color ? sub_style(subject.to_s, styles: (@theme && @theme[:subject]) || :bold) : subject) if subject
195
+ if subject
196
+ msg << (color ? sub_style(subject.to_s, (@theme.is_a?(::Hash) && @theme[:subject]) || :bold) : subject)
197
+ end
196
198
  msg << args.shift if msg.size == 1
197
199
  message(msg.join(' '), *args, hint: hint)
198
200
  end
@@ -225,7 +227,7 @@ module Squared
225
227
  end
226
228
 
227
229
  def emphasize(val, title: nil, footer: nil, right: false, cols: nil, sub: nil, pipe: nil,
228
- border: @theme && @theme[:border])
230
+ border: @theme.is_a?(::Hash) && @theme[:border])
229
231
  n = 0
230
232
  max = ->(a) { n = [n, a.max_by(&:size).size].max }
231
233
  set = ->(s) { Array(s).map(&:to_s).tap { |a| max.call(a) } }
@@ -290,7 +292,7 @@ module Squared
290
292
  else
291
293
  pipe = $stdout unless pipe.respond_to?(:puts)
292
294
  end
293
- pipe.puts out
295
+ pipe.puts(out)
294
296
  else
295
297
  err ? warn(out) : puts(out)
296
298
  end
@@ -55,9 +55,9 @@ module Squared
55
55
  raise_error 'empty selection list' if max == 0
56
56
  min = grep ? 1 : [min, max].min
57
57
  if auto
58
- msg = "#{msg + (force ? ':' : '?')} [#{min}-#{max}#{if (n = multiple)
59
- "|,#{n.is_a?(::Numeric) ? "{#{n}}" : ''}"
60
- end}] "
58
+ msg = "#{msg}: [#{min}-#{max}#{if multiple
59
+ "|,#{multiple.is_a?(::Numeric) ? "{#{multiple}}" : ''}"
60
+ end}] "
61
61
  end
62
62
  end
63
63
  valid = ->(s) { s.match?(/^\d+$/) && s.to_i.between?(min, max) }
@@ -29,7 +29,7 @@ module Squared
29
29
  r[7]
30
30
  end
31
31
  r[1] + (data ? data[2] : r[2]) + r[4] + shell_quote(opt, force: force, double: double, override: override)
32
- elsif option && val =~ /\A(-{0,2}[^\[\]=\s-][^\[\]=\s]*)=(.+)\z/m
32
+ elsif option && val =~ /\A(-{0,2}[^=\s-][^=\s]*)=(.+)\z/m
33
33
  return val if $2.match?(QUOTE_VALUE)
34
34
 
35
35
  "#{$1}=%s" % if $2.include?(' ')
@@ -53,7 +53,7 @@ module Squared
53
53
  return val if (!force && !val.include?(' ')) || val.empty?
54
54
 
55
55
  if option
56
- pat = /\A(?:-[^\[\]=\s-](?:=|\s+)?|(--)?[^\[\]=\s-][^\[\]=\s]*(?(1)(?:=|\s+)|=))(["']).+\2\z/m
56
+ pat = /\A(?:-[^=\s-](?:=|\s+)?|(--)?[^=\s-][^=\s]*(?(1)(?:=|\s+)|=))(["']).+\2\z/m
57
57
  return val if val.match?(pat)
58
58
  end
59
59
  q = ->(s) { s.gsub("'\\\\''", "'") }
@@ -80,7 +80,11 @@ module Squared
80
80
  end
81
81
  sep = unless flag.empty?
82
82
  if flag[0] == '-'
83
- flag[1] == '-' ? '=' : ' '
83
+ if flag[1] == '-'
84
+ '='
85
+ else
86
+ merge ? '' : ' '
87
+ end
84
88
  elsif flag.size == 1
85
89
  pre = '-'
86
90
  merge ? '' : ' '
@@ -119,6 +123,7 @@ module Squared
119
123
  end
120
124
 
121
125
  def fill_option(val, **kwargs)
126
+ return val unless val.is_a?(::String)
122
127
  return "-#{val}" if val.match?(/\A(?:[a-z]\d*|\d)\z/i)
123
128
 
124
129
  shell_escape(val.start_with?('-') ? val : "--#{val}", **kwargs)
@@ -12,15 +12,14 @@ module Squared
12
12
  include Rake::DSL
13
13
 
14
14
  class << self
15
- def parse(gem, namespace, ext = [pkg])
15
+ def parse(gem, namespace, ext = [gem])
16
16
  require gem
17
- obj = eval namespace
18
- Array(ext).each { |val| @@mime_obj[val] = [obj, ext] }
17
+ [eval(namespace), Array(ext)].tap do |data|
18
+ data.last.each { |key| @@mime_obj[key] = data }
19
+ end
19
20
  rescue LoadError, NameError => e
20
21
  warn e
21
22
  nil
22
- else
23
- @@mime_obj[ext.first]
24
23
  end
25
24
 
26
25
  def link(project, main = project.dependfile.basename, name = nil, **kwargs, &blk)
@@ -246,7 +245,7 @@ module Squared
246
245
  { pat: /\A((?~: ): )(-?[\d.]+)(\s*)\z/m, styles: theme[:number],
247
246
  index: 2 },
248
247
  { pat: /\A((?~: ): ")(.+)("\s*)\z/m, styles: theme[:string], index: 2 },
249
- { pat: /\A((?~: ): \{)(.+)(\}\s*)\z/m, styles: theme[:hash], index: 2 },
248
+ { pat: /\A((?~: ): \{)(.+)(}\s*)\z/m, styles: theme[:hash], index: 2 },
250
249
  { pat: /\A((?~: ): \[)(.+)(\]\s*)\z/m, styles: theme[:array],
251
250
  index: 2 },
252
251
  { pat: /\A((?~: ): )(true|false)(\s*)\z/m, styles: theme[:boolean],
@@ -263,7 +262,7 @@ module Squared
263
262
  symbolize = opts[:symbolize_names]
264
263
  keys.each do |key|
265
264
  begin
266
- items = key.split('.')
265
+ items = key.split('.').flat_map { |name| name =~ /^(.+)\[(\d+)\]$/ ? [$1, $2.to_i] : name }
267
266
  items = items.map(&:to_sym) if symbolize
268
267
  val = data.dig(*items)
269
268
  if val.nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Squared
4
- VERSION = '0.5.15'
4
+ VERSION = '0.5.17'
5
5
  end
@@ -497,7 +497,7 @@ module Squared
497
497
  if (base = task_base?(key))
498
498
  tasks << key if obj.has?(key, baseref)
499
499
  elsif (batch = series.batch_get(key))
500
- obj.allref.each do |ref|
500
+ obj.allref do |ref|
501
501
  next unless obj.has?(key, ref) && (data = batch[ref])
502
502
 
503
503
  data.each do |val|
@@ -516,7 +516,7 @@ module Squared
516
516
  if tasks.empty?
517
517
  return [] if (base && !obj.ref?(baseref)) || !(data = series.alias_get(key))
518
518
 
519
- obj.allref.each do |ref|
519
+ obj.allref do |ref|
520
520
  next unless obj.has?(key, ref) && (alt = data[ref])
521
521
 
522
522
  ret = task_resolve obj, alt
@@ -80,9 +80,9 @@ module Squared
80
80
  'asdf' => %i[set exec current]
81
81
  })
82
82
 
83
- attr_reader :name, :project, :workspace, :path, :theme, :group, :parent, :dependfile,
83
+ attr_reader :name, :workspace, :path, :theme, :group, :parent, :dependfile,
84
84
  :exception, :pipe, :verbose
85
- attr_accessor :global
85
+ attr_accessor :global, :project
86
86
 
87
87
  def initialize(workspace, path, name, *, group: nil, first: {}, last: {}, error: {}, common: ARG[:COMMON],
88
88
  **kwargs)
@@ -1075,8 +1075,8 @@ module Squared
1075
1075
  @log = Logger.new(enabled? ? @log.first : nil, **@log.last)
1076
1076
  end
1077
1077
 
1078
- def allref
1079
- @ref.reverse_each
1078
+ def allref(&blk)
1079
+ @ref.reverse_each(&blk)
1080
1080
  end
1081
1081
 
1082
1082
  def basepath(*args)
@@ -1090,7 +1090,7 @@ module Squared
1090
1090
  path.parent.ascend.each do |dir|
1091
1091
  target = dir.join(*args)
1092
1092
  return target if target.exist?
1093
- break if (ascend && dir.join(ascend).exist?) || workspace.root == dir || parent&.path == dir
1093
+ break if (ascend.is_a?(String) && dir.join(ascend).exist?) || workspace.root == dir || parent&.path == dir
1094
1094
  end
1095
1095
  ret
1096
1096
  end
@@ -1356,7 +1356,9 @@ module Squared
1356
1356
  end
1357
1357
 
1358
1358
  def print_error(*args, loglevel: Logger::WARN, **kwargs)
1359
- warn log_message(loglevel, *args, **kwargs) if warning?
1359
+ return unless warning?
1360
+
1361
+ warn log_message(loglevel, *args, **kwargs)
1360
1362
  end
1361
1363
 
1362
1364
  def print_item(*val, series: true)
@@ -1509,8 +1511,8 @@ module Squared
1509
1511
  "#{msg}#{!always && (!obj || obj == 0 || obj.to_s.empty?) ? '' : message(hint: message(title, obj.to_s))}"
1510
1512
  end
1511
1513
 
1512
- def append_repeat(flag, opts, target: @session)
1513
- opts.each { |val| target << shell_option(flag, val) }
1514
+ def append_repeat(flag, opts, target: @session, **kwargs)
1515
+ opts.each { |val| target << shell_option(flag, val, **kwargs) }
1514
1516
  end
1515
1517
 
1516
1518
  def append_hash(data, target: @session || [], build: false)
@@ -1536,6 +1538,8 @@ module Squared
1536
1538
  target << basic_option(key, val)
1537
1539
  when FalseClass
1538
1540
  target << shell_option(key).sub(/^--(?!no-)/, '--no-')
1541
+ when Pathname
1542
+ target << shell_option(key, val, escape: false)
1539
1543
  else
1540
1544
  target << shell_option(key, val.is_a?(String) ? val : nil)
1541
1545
  end
@@ -1594,18 +1598,18 @@ module Squared
1594
1598
  return if list.empty?
1595
1599
 
1596
1600
  kwargs[:ignore] = false if no && !kwargs.key?(:ignore)
1597
- [].tap do |ret|
1598
- list.flatten.each do |flag|
1599
- next unless (val = option(flag, target: target, **kwargs))
1601
+ ret = []
1602
+ list.flatten.each do |flag|
1603
+ next unless (val = option(flag, target: target, **kwargs))
1600
1604
 
1601
- if no && val == '0'
1602
- flag = "no-#{flag}"
1603
- val = nil
1604
- end
1605
- ret << shell_option(flag, equals ? val : nil, escape: escape, quote: quote, force: force)
1605
+ if no && val == '0'
1606
+ flag = "no-#{flag}"
1607
+ val = nil
1606
1608
  end
1607
- ret.each { |val| target << val } unless ret.empty?
1609
+ ret << shell_option(flag, equals ? val : nil, escape: escape, quote: quote, force: force)
1608
1610
  end
1611
+ ret.each { |val| target << val } unless ret.empty?
1612
+ ret
1609
1613
  end
1610
1614
 
1611
1615
  def append_nocolor(target: @session)
@@ -1653,9 +1657,9 @@ module Squared
1653
1657
  end
1654
1658
 
1655
1659
  def collect_hash(data, pass: [])
1656
- [].tap do |ret|
1657
- data.each { |key, val| ret.concat(val) unless pass.include?(key) }
1658
- end
1660
+ ret = []
1661
+ data.each { |key, val| ret.concat(val) unless pass.include?(key) }
1662
+ ret
1659
1663
  end
1660
1664
 
1661
1665
  def parse_json(val, kind: Hash, hint: nil)
@@ -1908,16 +1912,15 @@ module Squared
1908
1912
  end
1909
1913
 
1910
1914
  def pwd_set(pass: false, dryrun: false, from: nil)
1911
- pwd = Dir.pwd
1912
- return yield if (path.to_s == pwd || pass == true) && (workspace.mri? || !workspace.windows?)
1915
+ return yield if (path.to_s == Dir.pwd || pass == true) && (workspace.mri? || !workspace.windows?)
1913
1916
 
1914
- Dir.chdir path
1915
- ret = yield
1916
- Dir.chdir pwd
1917
+ pwd = Dir.pwd
1918
+ Dir.chdir(path)
1919
+ yield
1917
1920
  rescue StandardError => e
1918
1921
  on_error(e, from, dryrun: dryrun)
1919
- else
1920
- ret
1922
+ ensure
1923
+ Dir.chdir(pwd) if pwd
1921
1924
  end
1922
1925
 
1923
1926
  def run_set(cmd, val = nil, opts: nil, **)
@@ -2097,7 +2100,7 @@ module Squared
2097
2100
 
2098
2101
  def runnable?(val)
2099
2102
  case val
2100
- when String, Enumerable, Proc, Method
2103
+ when String, Enumerable, Proc, Method, Struct
2101
2104
  true
2102
2105
  else
2103
2106
  false
@@ -2159,14 +2162,9 @@ module Squared
2159
2162
  end
2160
2163
 
2161
2164
  def has_value?(data, other)
2162
- case data
2163
- when Hash
2164
- other.is_a?(Enumerable) ? other.any? { |obj| data.value?(obj) } : data.value?(other)
2165
- when Enumerable
2166
- other.is_a?(Enumerable) ? other.any? { |obj| data.include?(obj) } : data.include?(other)
2167
- else
2168
- false
2169
- end
2165
+ return false unless data.is_a?(Enumerable)
2166
+
2167
+ other.is_a?(Enumerable) ? other.any? { |obj,| data.include?(obj) } : data.include?(other)
2170
2168
  end
2171
2169
 
2172
2170
  def variables
@@ -386,7 +386,6 @@ module Squared
386
386
  case flag
387
387
  when :run, :create, :exec
388
388
  if rc && !op.arg?('mount')
389
- run = VAL_DOCKER[:run]
390
389
  all = collect_hash VAL_DOCKER[:run]
391
390
  delim = Regexp.new(",\\s*(?=#{all.join('|')})")
392
391
  Array(@mounts).each do |val|
@@ -403,8 +402,8 @@ module Squared
403
402
  end
404
403
  elsif all.include?(k)
405
404
  unless type
406
- run.each_pair do |key, val|
407
- next unless val.include?(k)
405
+ VAL_DOCKER[:run].each_pair do |key, a|
406
+ next unless a.include?(k)
408
407
 
409
408
  type = key.to_s unless key == :common
410
409
  break
@@ -822,7 +821,7 @@ module Squared
822
821
  end
823
822
  cmd.merge(Array(out).map! { |val| parse.call(val) })
824
823
  cmd << args
825
- print_success if success?(run(cmd), ctx.start_with?(/(?:network|tag|save)/))
824
+ print_success if success?(run(cmd), ctx.start_with?(/network|tag|save/))
826
825
  end
827
826
  end
828
827
 
@@ -134,7 +134,7 @@ module Squared
134
134
  File.write(@revfile, JSON.pretty_generate(@revdoc))
135
135
  rescue StandardError => e
136
136
  log&.debug e
137
- warn log_message(Logger::WARN, e, pass: true) if warning?
137
+ warn log_message(Logger::WARN, e, pass: true) if warning
138
138
  ensure
139
139
  @revlock = false
140
140
  end
@@ -675,7 +675,7 @@ module Squared
675
675
  branch(flag, target: target, ref: ref, remote: remote)
676
676
  end
677
677
  when :delete
678
- format_desc action, flag, '(^~)name*,:?'
678
+ format_desc action, flag, '[^~]name*,:?'
679
679
  task flag do |_, args|
680
680
  refs = args.to_a
681
681
  if refs.empty? || (r = refs.last == ':')
@@ -1238,7 +1238,7 @@ module Squared
1238
1238
  end
1239
1239
  end
1240
1240
  start = time_epoch
1241
- build(@output, sync: sync, from: :'git:revbuild')
1241
+ build(*@output, sync: sync, from: :'git:revbuild')
1242
1242
  rescue StandardError => e
1243
1243
  print_error(e, pass: true)
1244
1244
  else
@@ -1447,7 +1447,6 @@ module Squared
1447
1447
  end
1448
1448
  origin = readline('Enter an upstream', force: true)
1449
1449
  end
1450
- raise_error('missing remote name', hint: origin) unless origin.include?('/')
1451
1450
  upstream = true
1452
1451
  end
1453
1452
  break
@@ -1495,7 +1494,8 @@ module Squared
1495
1494
  case flag
1496
1495
  when :commit, :'no-commit'
1497
1496
  op = OptionPartition.new(opts, OPT_GIT[:merge], cmd, project: self, no: OPT_GIT[:no][:merge])
1498
- op << "--#{flag}" << '--'
1497
+ op << "--#{flag}"
1498
+ op.delim
1499
1499
  if branch
1500
1500
  op << branch
1501
1501
  op.clear(pass: false)
@@ -1700,7 +1700,7 @@ module Squared
1700
1700
  cmd, opts = git_session('rev-parse', opts: opts)
1701
1701
  case flag
1702
1702
  when :commit
1703
- cmd << ((n = size.to_i) > 0 ? basic_option('short', [n, 5].max) : '--verify')
1703
+ cmd << (size.to_i.zero? ? '--verify' : basic_option('short', [size.to_i, 5].max))
1704
1704
  append_commit(ref, head: true)
1705
1705
  when :branch
1706
1706
  cmd << '--abbrev-ref'
@@ -1749,7 +1749,7 @@ module Squared
1749
1749
  case flag
1750
1750
  when :blame
1751
1751
  raise_error 'no file found' unless (n = op.index { |s| basepath(s).file? })
1752
- op << '--' << shell_quote(basepath(op.delete_at(n)))
1752
+ op.delim << shell_quote(basepath(op.delete_at(n)))
1753
1753
  op.clear
1754
1754
  when :revert
1755
1755
  if VAL_GIT[:rebase][:send].any? { |val| op.arg?(val) }
@@ -1764,12 +1764,11 @@ module Squared
1764
1764
  grep, list = op.partition { |val| OptionPartition.pattern?(val) }
1765
1765
  unless grep.empty? && !list.empty?
1766
1766
  grep.map! { |val| Regexp.new(val[1..-2]) }
1767
- files = [].tap do |out|
1768
- status_data.each do |a, b|
1769
- next if b.strip.empty? || (!grep.empty? && grep.none? { |pat| pat.match?(a) })
1767
+ files = []
1768
+ status_data.each do |a, b|
1769
+ next if b.strip.empty? || (!grep.empty? && grep.none? { |pat| pat.match?(a) })
1770
1770
 
1771
- out << "#{sub_style(b, styles: color(:red))} #{a}"
1772
- end
1771
+ files << "#{sub_style(b, styles: color(:red))} #{a}"
1773
1772
  end
1774
1773
  unless files.empty?
1775
1774
  files = choice_index('Select files', files, multiple: true, force: true, trim: /^\S+\s/,
@@ -1925,7 +1924,7 @@ module Squared
1925
1924
  end
1926
1925
  args = []
1927
1926
  args << quote_option('sort', sort) if sort
1928
- args << shell_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
1927
+ args << basic_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
1929
1928
  choice_index(msg, foreachref(type, *args, format: format), trim: trim, **kwargs)
1930
1929
  end
1931
1930
 
@@ -1958,13 +1957,13 @@ module Squared
1958
1957
  end
1959
1958
 
1960
1959
  def status_data(*args)
1961
- [].tap do |ret|
1962
- git_spawn('status -z -uall', *args).split("\x0").each do |line|
1963
- next unless line =~ /^(.)(.) (.+)$/
1960
+ ret = []
1961
+ git_spawn('status -z -uall', *args).split("\x0").each do |line|
1962
+ next unless line =~ /^(.)(.) (.+)$/
1964
1963
 
1965
- ret << [$3, $2, $1]
1966
- end
1964
+ ret << [$3, $2, $1]
1967
1965
  end
1966
+ ret
1968
1967
  end
1969
1968
 
1970
1969
  def append_pull(opts, list, target: @session, flag: nil, no: nil, remote: nil, from: nil)
@@ -2039,7 +2038,9 @@ module Squared
2039
2038
 
2040
2039
  def append_message(val = nil, target: @session)
2041
2040
  val = messageopt if val.to_s.empty?
2042
- target << quote_option('message', val) if val
2041
+ return unless val
2042
+
2043
+ target << quote_option('message', val)
2043
2044
  end
2044
2045
 
2045
2046
  def append_head(val = nil, target: @session)
@@ -2123,7 +2124,9 @@ module Squared
2123
2124
  end
2124
2125
 
2125
2126
  def repotrack(origin, branch, quote: true)
2126
- i = origin.index('/')
2127
+ unless origin && branch && (i = origin.index('/'))
2128
+ raise_error(ArgumentError, "missing #{origin ? 'branch' : 'remote'} name", hint: origin)
2129
+ end
2127
2130
  branch = "#{branch}:#{origin[(i + 1)..-1]}" unless origin.end_with?("/#{branch}")
2128
2131
  [origin[0..(i - 1)], branch].tap { |ret| ret.map! { |val| shell_quote(val) } if quote }
2129
2132
  end
@@ -6,18 +6,19 @@ module Squared
6
6
  class Node < Git
7
7
  OPT_NPM = {
8
8
  common: %w[dry-run=!? include-workspace-root=!? loglevel=b workspaces=!? w|workspace=v].freeze,
9
- install: %w[package-lock-only=!? prefer-dedupe=!? cpu=b libc=b os=b].freeze,
10
- install_base: %w[audit=! bin-links=! fund=! ignore-scripts=!? install-links=!? package-lock=!
11
- strict-peer-deps=!? include=b install-strategy=b omit=b].freeze,
9
+ install: %w[package-lock-only=!? prefer-dedupe=!? E|save-exact=!? before=q cpu=b libc=b os=b].freeze,
10
+ install_base: %w[audit=! bin-links=! foreground-scripts=!? fund=! ignore-scripts=!? install-links=!?
11
+ package-lock=! strict-peer-deps=!? include=b install-strategy=b omit=b].freeze,
12
12
  install_no: %w[audit bin-links fund package-lock].freeze,
13
- install_as: %w[no-save save-bundle save-dev save-optional save-peer save-prod before=q foreground-scripts=!?
14
- g|global=!? S|save=!? E|save-exact=!?].freeze,
13
+ install_as: %w[no-save B|save-bundle D|save-dev O|save-optional save-peer P|save-prod g|global=!?
14
+ S|save=!?].freeze,
15
15
  run: %w[foreground-scripts=!? if-present=!? ignore-scripts=!? script-shell=p].freeze,
16
16
  exec: %w[c|call=q package=b].freeze,
17
17
  pack: %w[ignore-scripts=!? json=!? pack-destination=p].freeze
18
18
  }.freeze
19
19
  OPT_PNPM = {
20
- common: %w[aggregate-output color no-color stream use-stderr C|dir=p loglevel=b w|workspace-root].freeze,
20
+ common: %w[aggregate-output color ignore-workspace-root-check no-color stream use-stderr C|dir=p loglevel=b
21
+ r|recursive w|workspace-root].freeze,
21
22
  cpu: %w[cpu=b libc=b os=b].freeze,
22
23
  filter: %w[fail-if-no-match changed-files-ignore-pattern=q filter=q filter-prod=q test-pattern=q].freeze,
23
24
  install: %w[fix-lockfile force ignore-pnpmfile ignore-workspace lockfile-only merge-git-branch-lockfiles
@@ -28,12 +29,12 @@ module Squared
28
29
  reporter=b].freeze,
29
30
  install_base: %w[global-dir ignore-scripts offline prefer-offline store-dir=p virtual-store-dir=p].freeze,
30
31
  install_no: %w[frozen-lockfile verify-store-integrity].freeze,
31
- install_as: %w[D|dev global-dir no-optional P|prod r|recursive].freeze,
32
+ install_as: %w[D|dev no-optional P|prod].freeze,
32
33
  update: %w[g|global i|interactive L|latest depth=i].freeze,
33
34
  dedupe: %w[check].freeze,
34
- run: %w[if-present no-bail parallel r|recursive report-summary reporter-hide-prefix resume-from
35
+ run: %w[if-present no-bail parallel report-summary reporter-hide-prefix resume-from
35
36
  sequential].freeze,
36
- exec: %w[no-reporter-hide-prefix parallel r|recursive report-summary resume-from c|shell-mode].freeze,
37
+ exec: %w[no-reporter-hide-prefix parallel report-summary resume-from c|shell-mode].freeze,
37
38
  pack: %w[json pack-destination=p pack-gzip-level=i].freeze
38
39
  }.freeze
39
40
  OPT_YARN = {
@@ -159,7 +160,8 @@ module Squared
159
160
  elsif exception
160
161
  indexerror n, list
161
162
  else
162
- next log.warn "run script #{n} of #{list.size} (out of range)"
163
+ log.warn "run script #{n} of #{list.size} (out of range)"
164
+ next
163
165
  end
164
166
  else
165
167
  opts << val
@@ -197,11 +199,11 @@ module Squared
197
199
  if op.empty?
198
200
  op << package
199
201
  if (args = readline('Enter arguments', force: false))
200
- op << '--' unless pnpm?
202
+ op.delim unless pnpm?
201
203
  op << args
202
204
  end
203
205
  else
204
- op << '--' unless pnpm?
206
+ op.delim unless pnpm?
205
207
  op << package << op.join(' ')
206
208
  end
207
209
  else
@@ -280,6 +282,8 @@ module Squared
280
282
 
281
283
  def copy(from: 'build', into: 'node_modules', scope: nil, also: nil, create: nil, files: nil, workspace: false,
282
284
  link: false, force: false, override: false, sync: invoked_sync?('copy'), **kwargs)
285
+ return if @copy == false
286
+
283
287
  glob = kwargs[:include]
284
288
  pass = kwargs[:exclude]
285
289
  if @copy && !override
@@ -296,8 +300,6 @@ module Squared
296
300
  create = @copy[:create] if @copy.key?(:create)
297
301
  glob = @copy[:include] if @copy.key?(:include)
298
302
  pass = @copy[:exclude] if @copy.key?(:exclude)
299
- elsif @copy == false
300
- return
301
303
  end
302
304
  items = []
303
305
  if build? && path != @workspace.home && @workspace.home?
@@ -445,11 +447,12 @@ module Squared
445
447
  if flag == :add
446
448
  cmd << 'add' << "--save-#{save}"
447
449
  cmd << '--save-exact' if exact
450
+ option('allow-build') { |val| cmd << quote_option('allow-build', val) }
448
451
  else
449
452
  cmd << 'install'
450
453
  append_platform
451
454
  end
452
- option('public-hoist-pattern', ignore: false) do |val|
455
+ option('public-hoist-pattern') do |val|
453
456
  split_escape(val).each { |opt| cmd << shell_option('public-hoist-pattern', opt) }
454
457
  end
455
458
  cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0')
@@ -459,7 +462,6 @@ module Squared
459
462
  if flag == :add
460
463
  cmd << "--save-#{save}"
461
464
  cmd << '--save-exact' if exact
462
- cmd.merge(packages.map { |pkg| shell_quote(pkg) })
463
465
  else
464
466
  append_platform
465
467
  end
@@ -468,7 +470,8 @@ module Squared
468
470
  append_nocolor
469
471
  end
470
472
  append_loglevel
471
- run(from: :depend, sync: sync)
473
+ cmd.merge(packages.map { |pkg| shell_quote(pkg) }) if flag == :add
474
+ run(from: flag || :depend, sync: sync)
472
475
  end
473
476
  end
474
477
 
@@ -721,7 +724,7 @@ module Squared
721
724
  else
722
725
  cmd = session 'npm', flag
723
726
  list = OPT_NPM[:install_base] + OPT_NPM.fetch(flag, []) + OPT_NPM[:common]
724
- list.concat(OPT_NPM[:install_as]) unless flag == :dedupe
727
+ list.concat(OPT_NPM[:install_as]) if flag == :install || flag == :update
725
728
  no = OPT_NPM[:install_no]
726
729
  end
727
730
  op = OptionPartition.new(opts, list, cmd, no: no, project: self)
@@ -741,13 +744,13 @@ module Squared
741
744
  append_platform if flag == :install
742
745
  append_nocolor
743
746
  append_loglevel
744
- if flag == :dedupe
747
+ if flag == :dedupe || pnpm?
745
748
  op.clear
746
749
  else
747
750
  op.append(quote: true)
748
751
  end
749
- op.clear(errors: true)
750
752
  end
753
+ op.clear(errors: true)
751
754
  run(from: from || :"package:#{flag}")
752
755
  end
753
756
 
@@ -862,7 +865,7 @@ module Squared
862
865
  end
863
866
 
864
867
  def outdated?
865
- dependfile.exist?
868
+ dependfile.exist? && !task_pass?('outdated')
866
869
  end
867
870
 
868
871
  def update?
@@ -1040,7 +1043,7 @@ module Squared
1040
1043
 
1041
1044
  def append_loglevel(target: @session)
1042
1045
  level = env('NODE_LOGLEVEL')
1043
- silent = !verbose || level == 'silent'
1046
+ silent = verbosetype == 0 || level == 'silent'
1044
1047
  return unless silent || level
1045
1048
 
1046
1049
  if yarn?
@@ -624,7 +624,7 @@ module Squared
624
624
  end
625
625
 
626
626
  def outdated?
627
- dependtype > 0
627
+ dependtype > 0 && !task_pass?('outdated')
628
628
  end
629
629
 
630
630
  private
@@ -636,7 +636,7 @@ module Squared
636
636
  def python_session(*cmd, opts: nil)
637
637
  return session('python', *preopts(quiet: false), *cmd, path: venv.nil?) unless opts
638
638
 
639
- op = OptionPartition.new(opts, OPT_PYTHON[:common], project: self, single: /\A(?:v+|OO)\z/)
639
+ op = OptionPartition.new(opts, OPT_PYTHON[:common], project: self, single: singleopt(:python))
640
640
  ret = session('python', *op.to_a, *cmd, path: venv.nil?)
641
641
  [ret, op.extras]
642
642
  end
@@ -733,7 +733,7 @@ module Squared
733
733
  quote_option('cache-dir', basepath(val))
734
734
  end
735
735
  end
736
- option('proxy', target: target) { |val| target << shell_option('proxy', val) }
736
+ option('proxy', target: target) { |val| target << quote_option('proxy', val) }
737
737
  option('python', target: target) { |val| target << quote_option('python', basepath(val)) }
738
738
  append_nocolor(target: target)
739
739
  end
@@ -814,7 +814,7 @@ module Squared
814
814
  def singleopt(flag = nil)
815
815
  case flag
816
816
  when :python
817
- /\A(?:v+|q+|b+)\z/
817
+ /\A(?:v+|q+|b+|V+|O+)\z/
818
818
  when :twine
819
819
  nil
820
820
  else
@@ -294,6 +294,8 @@ module Squared
294
294
  end
295
295
 
296
296
  def copy(from: gemlib, into: @gemdir, override: false, **kwargs)
297
+ return if @copy == false
298
+
297
299
  glob = kwargs[:include]
298
300
  pass = kwargs[:exclude]
299
301
  if @copy && !override
@@ -303,8 +305,6 @@ module Squared
303
305
  glob = @copy[:include] if @copy.key?(:include)
304
306
  pass = @copy[:exclude] if @copy.key?(:exclude)
305
307
  into = @copy[:into] if @copy.key?(:into)
306
- elsif @copy == false
307
- return
308
308
  end
309
309
  return unless into
310
310
 
@@ -468,13 +468,15 @@ module Squared
468
468
  case flag
469
469
  when :file, :script
470
470
  op = OptionPartition.new(opts, OPT_RUBY[:ruby], ruby_session, project: self, args: true)
471
- if file
472
- op.unshift(shell_quote(basepath(file)))
473
- elsif command
471
+ if command
474
472
  op << quote_option('e', command, option: false)
473
+ elsif file
474
+ op.unshift(basepath(file))
475
+ end
476
+ unless op.arg?('e')
477
+ op.push(args) if args
478
+ op.append(delim: true, escape: false, quote: false) unless op.empty?
475
479
  end
476
- op.push(args) if args
477
- op.append(delim: true, escape: false, quote: false) unless op.empty?
478
480
  when :version
479
481
  pwd_set do
480
482
  out = []
@@ -601,7 +603,6 @@ module Squared
601
603
  when :install, :update
602
604
  list.concat(OPT_GEM[:install_base])
603
605
  end
604
- cmd.merge(preopts)
605
606
  op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag])
606
607
  op.each do |opt|
607
608
  if !opt.match?(/\A[A-Za-z\d][A-Za-z\d_.-]*\z/) && %i[install uninstall update pristine].include?(flag)
@@ -802,7 +803,7 @@ module Squared
802
803
  else
803
804
  [name[0, n], name[(n + 1)..-1]]
804
805
  end
805
- op.adjoin(pre, shell_option('version', ver))
806
+ op.adjoin(pre, basic_option('version', ver))
806
807
  .clear
807
808
  elsif flag == :install
808
809
  op.append_any
@@ -810,7 +811,7 @@ module Squared
810
811
  op.append
811
812
  end
812
813
  op.clear(errors: true)
813
- op << '--' << readline('Enter command [args]', force: true) if flag == :install && op.remove(':')
814
+ op.delim << readline('Enter command [args]', force: true) if flag == :install && op.remove(':')
814
815
  else
815
816
  op.append
816
817
  end
@@ -858,7 +859,7 @@ module Squared
858
859
  r.each { |val| op << shell_option('r', val, merge: true) }
859
860
  Array(path).each { |val| op << quote_option('I', val, merge: true) }
860
861
  if args
861
- op << '--' << args
862
+ op.delim << args
862
863
  op.clear
863
864
  else
864
865
  op.append(delim: true)
@@ -867,13 +868,8 @@ module Squared
867
868
  end
868
869
 
869
870
  def gemspec
870
- return @gemspec unless @gemspec.nil?
871
-
872
- @gemspec = if gemfile
873
- Gem::Specification.load(gemfile.to_s) rescue false
874
- else
875
- false
876
- end
871
+ @gemspec = !gemfile.nil? && Gem::Specification.load(gemfile.to_s) rescue false if @gemspec.nil?
872
+ @gemspec || nil
877
873
  end
878
874
 
879
875
  def gemname
@@ -963,7 +959,7 @@ module Squared
963
959
  end
964
960
 
965
961
  def outdated?
966
- dependtype > 0
962
+ dependtype > 0 && !task_pass?('outdated')
967
963
  end
968
964
 
969
965
  private
@@ -997,18 +993,11 @@ module Squared
997
993
  end
998
994
 
999
995
  def gem_session(*cmd, **kwargs)
1000
- ret = session('gem', *cmd, **kwargs)
1001
- return ret if cmd.empty?
1002
-
1003
- ret.merge(preopts)
996
+ session('gem', *cmd, *preopts, **kwargs)
1004
997
  end
1005
998
 
1006
999
  def bundle_session(*cmd, **kwargs)
1007
- ret = session('bundle', *cmd, **kwargs)
1008
- return ret if cmd.empty?
1009
-
1010
- append_nocolor
1011
- ret.merge(preopts)
1000
+ session('bundle', *cmd, *preopts, **kwargs).tap { append_nocolor }
1012
1001
  end
1013
1002
 
1014
1003
  def rake_session(*cmd, **kwargs)
@@ -1054,7 +1043,7 @@ module Squared
1054
1043
  end
1055
1044
 
1056
1045
  def preopts
1057
- verbosetype > 1 && !session_arg?('quiet') ? ['--verbose'] : []
1046
+ verbosetype > 1 ? ['--verbose'] : []
1058
1047
  end
1059
1048
 
1060
1049
  def variables
@@ -1062,11 +1051,11 @@ module Squared
1062
1051
  end
1063
1052
 
1064
1053
  def rakefile
1065
- return @rakefile unless @rakefile.nil?
1066
-
1067
- @rakefile = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }.yield_self do |file|
1068
- file ? basepath(file) : false
1054
+ if @rakefile.nil?
1055
+ file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }
1056
+ @rakefile = !file.nil? && basepath(file)
1069
1057
  end
1058
+ @rakefile || nil
1070
1059
  end
1071
1060
 
1072
1061
  def rakepwd
@@ -1095,16 +1084,16 @@ module Squared
1095
1084
  end
1096
1085
 
1097
1086
  def gemfile
1098
- return @gemfile unless @gemfile.nil?
1099
-
1100
- @gemfile = [project, name].map! { |val| basepath("#{val}.gemspec") }
1101
- .concat(path.glob('*.gemspec'))
1102
- .find(&:exist?) || false
1087
+ if @gemfile.nil?
1088
+ @gemfile = [project, name].map! { |val| basepath("#{val}.gemspec") }
1089
+ .concat(path.glob('*.gemspec'))
1090
+ .find(&:exist?) || false
1091
+ end
1092
+ @gemfile || nil
1103
1093
  end
1104
1094
 
1105
1095
  def gemlib
1106
- @gemlib ||= begin
1107
- lib = Set.new(['lib'])
1096
+ @gemlib ||= Set.new(['lib']).yield_self do |lib|
1108
1097
  if (spec = gemspec)
1109
1098
  lib.merge(spec.require_paths || [])
1110
1099
  end
@@ -1117,7 +1106,9 @@ module Squared
1117
1106
  end
1118
1107
 
1119
1108
  def gemdir?
1120
- !@gemdir.nil? && @gemdir.exist? && !@gemdir.empty?
1109
+ return false unless @gemdir
1110
+
1111
+ @gemdir.exist? && !@gemdir.empty?
1121
1112
  end
1122
1113
  end
1123
1114
 
@@ -10,9 +10,9 @@ module Squared
10
10
  include Common::Shell
11
11
  extend Forwardable
12
12
 
13
- OPT_NAME = /\A(?:(--)|-)((?(1)[^\[\]=\s-][^\[\]=\s]*|[^\[\]=\s-]))\z/
14
- OPT_VALUE = /\A-{0,2}([^\[\]=\s-][^\[\]=\s]*)(?:=|\s+)(\S.*)\z/
15
- OPT_SINGLE = /\A-([^\[\]=\s-])(.+)\z/
13
+ OPT_NAME = /\A(?:(--)|-)((?(1)[^=\s-][^=\s]*|[^=\s-]))\z/
14
+ OPT_VALUE = /\A-{0,2}([^=\s-][^=\s]*)(?:=|\s+)(\S.*)\z/
15
+ OPT_SINGLE = /\A-([^=\s-])(.+)\z/
16
16
  private_constant :OPT_NAME, :OPT_VALUE, :OPT_SINGLE
17
17
 
18
18
  class << self
@@ -29,15 +29,15 @@ module Squared
29
29
  pat, s = Array(strip)
30
30
  ret.map! { |val| val.is_a?(String) ? val.gsub(pat, s || '') : val }
31
31
  end
32
- if escape || quote
33
- ret.map! do |val|
34
- if opt?(val)
35
- val
36
- elsif escape
37
- shell_escape(val, quote: quote, double: double)
38
- else
39
- shell_quote(val, force: force, double: double)
40
- end
32
+ ret.map! do |val|
33
+ next val if opt?(val)
34
+
35
+ if quote || val.is_a?(Pathname)
36
+ shell_quote(val, force: force, double: double)
37
+ elsif escape
38
+ shell_escape(val, quote: quote, double: double)
39
+ else
40
+ val
41
41
  end
42
42
  end
43
43
  if target.is_a?(Set)
@@ -103,7 +103,7 @@ module Squared
103
103
  end
104
104
 
105
105
  def pattern?(val)
106
- val.match?(/(?:\A\^|\$\z)/) || val.match?(/(?:\.[*+]|\(\?:|\\[dsw]|\[.+\]|\{\d+,?\d*\})/)
106
+ val.match?(/(?:\A\^|\$\z)/) || val.match?(/(?:\.[*+]|\(\?:|\\[dsw]|\[.+\]|\{\d+,?\d*})/)
107
107
  end
108
108
 
109
109
  private
@@ -134,7 +134,7 @@ module Squared
134
134
  attr_reader :target, :extras, :found, :errors, :values, :project, :path
135
135
 
136
136
  def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
137
- :merge, :delete, :delete?, :delete_if, :grep, :grep_v, :inspect, :to_a, :to_s
137
+ :merge, :compact, :delete, :delete?, :delete_if, :grep, :grep_v, :inspect, :to_a, :to_s
138
138
  def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :last, :shift, :unshift,
139
139
  :pop, :push, :concat, :index, :join, :map, :map!, :detect, :select, :select!, :reject, :size,
140
140
  :delete_at
@@ -374,7 +374,7 @@ module Squared
374
374
 
375
375
  def adjoin(*args, with: nil, start: false)
376
376
  i = -1
377
- temp = to_a
377
+ temp = compact
378
378
  if with
379
379
  pat = case with
380
380
  when String, Symbol
@@ -393,11 +393,11 @@ module Squared
393
393
  else
394
394
  temp.each_with_index do |val, index|
395
395
  if i == 0
396
- next unless val.start_with?('-')
396
+ next unless val.is_a?(String) && val.start_with?('-')
397
397
 
398
398
  i = index
399
399
  break
400
- elsif index > 0 && !val.start_with?('-')
400
+ elsif index > 0 && !val.to_s.start_with?('-')
401
401
  if start
402
402
  i = index + (start.is_a?(Numeric) ? start : 1)
403
403
  break
@@ -431,6 +431,11 @@ module Squared
431
431
  self
432
432
  end
433
433
 
434
+ def delim
435
+ add '--'
436
+ self
437
+ end
438
+
434
439
  def splice(*exclude, quote: true, delim: true, path: false, pattern: false, &blk)
435
440
  found, other = if block_given?
436
441
  partition(&blk)
@@ -526,6 +531,7 @@ module Squared
526
531
  end
527
532
 
528
533
  def windows?
534
+ require 'rake'
529
535
  Rake::Win32.windows?
530
536
  end
531
537
  end
@@ -539,7 +545,7 @@ module Squared
539
545
 
540
546
  attr_reader :delim, :extras
541
547
 
542
- def initialize(data = [], delim: ' ', partition: '--', uniq: /\A--?[^\[\]=\s-][^\[\]=\s]*(?:=|\s+)\S/)
548
+ def initialize(data = [], delim: ' ', partition: '--', uniq: /\A--?[^=\s-][^=\s]*(?:=|\s+)\S/)
543
549
  @delim = delim
544
550
  @partition = partition
545
551
  @uniq = uniq
@@ -547,13 +553,17 @@ module Squared
547
553
  super(data.compact)
548
554
  end
549
555
 
556
+ def compact
557
+ to_ary.map!(&:to_s).reject(&:empty?)
558
+ end
559
+
550
560
  def last(val, pat)
551
561
  (@last ||= []).append([val, pat, $1]) if val =~ pat
552
562
  self << val
553
563
  end
554
564
 
555
565
  def pass(&blk)
556
- ret = to_ary.map!(&:to_s).reject(&:empty?)
566
+ ret = compact
557
567
  @last&.each do |val, pat, key|
558
568
  i = []
559
569
  j = nil
@@ -627,8 +637,8 @@ module Squared
627
637
  extras!(obj) || super
628
638
  end
629
639
 
630
- def add?(obj)
631
- extras!(obj) || super
640
+ def size
641
+ super + extras.size
632
642
  end
633
643
 
634
644
  def to_a
@@ -636,21 +646,24 @@ module Squared
636
646
  end
637
647
 
638
648
  def to_s
639
- pass.join(@delim)
649
+ to_a.join(@delim)
640
650
  end
641
651
 
642
652
  def to_enum(*args)
643
- pass.to_enum(*args)
653
+ to_a.to_enum(*args)
644
654
  end
645
655
 
646
656
  def to_json(*args)
647
- pass.to_json(*args)
657
+ to_a.to_json(*args)
648
658
  end
649
659
 
650
660
  def to_yaml(*args)
651
- pass.to_yaml(*args)
661
+ to_a.to_yaml(*args)
652
662
  end
653
663
 
664
+ alias add :<<
665
+ alias add? :<<
666
+
654
667
  private
655
668
 
656
669
  def extras!(obj)
@@ -132,20 +132,20 @@ module Squared
132
132
  task 'all' do |_, args|
133
133
  stage ||= 'all'
134
134
  ns['sync'].invoke(*args.to_a)
135
- next if (stage = env('REPO_STAGE')) == '1'
135
+ next if (n = env('REPO_STAGE')) == '1'
136
136
 
137
137
  @project.select do |_, proj|
138
138
  next unless proj.enabled?(proj.workspace.baseref) && proj.global
139
139
 
140
140
  proj.depend(sync: true) if proj.depend?
141
- next if stage == '2'
141
+ next if n == '2'
142
142
 
143
143
  proj.build?
144
144
  end
145
145
  .each_value do |proj|
146
146
  proj.build(sync: true)
147
- next if stage == '3'
148
- next unless proj.copy? && (proj.dev? || stage == '4')
147
+ next if n == '3'
148
+ next unless proj.copy? && (proj.dev? || n == '4')
149
149
 
150
150
  if (ws = proj.workspace).task_defined?(target = task_join(proj.name, 'copy'))
151
151
  task_invoke(target, **ws.invokeargs)
@@ -158,7 +158,7 @@ module Squared
158
158
  desc.call("init[manifest?=#{target},groups?,{0}]", target)
159
159
  task 'init' do |_, args|
160
160
  args = args.to_a
161
- u = env('REPO_URL') || manifest_url
161
+ u = env('REPO_GIT') || manifest_url
162
162
  m = args.first && !opts.include?(args.first) ? args.shift : target
163
163
  g = args.first && !opts.include?(args.first) ? args.shift : nil
164
164
  g = case (val = env('REPO_GROUPS'))
@@ -251,7 +251,9 @@ module Squared
251
251
  end
252
252
 
253
253
  def repo?
254
- !manifest_url.nil? && (repo_install? || @repo_override == true)
254
+ return false unless manifest_url && !windows?
255
+
256
+ repo_install? || @repo_override == true
255
257
  end
256
258
 
257
259
  def repo_submodules?(val = false)
@@ -5,12 +5,14 @@ module Squared
5
5
  class << self
6
6
  include Common
7
7
 
8
- def resolve(*args)
8
+ def resolve(*args, base: '..')
9
+ values = __get__(:project).values
9
10
  ret = args.map do |id|
10
11
  if id.is_a?(Symbol)
11
12
  project id
12
13
  else
13
- __get__(:project).find { |_, val| File.expand_path(val.path) == File.expand_path(id, __dir__) }
14
+ values.find { |proj| proj.name == id } || values.find { |proj| proj.project == id } ||
15
+ values.find { |proj| proj.path.to_s == File.expand_path(id, base) }
14
16
  end
15
17
  end
16
18
  ret.size == 1 ? ret.first : ret
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.15
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham