squared 0.2.2 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82c53d370d6535fd30824fafd72a2f68fd7db161600d2740fd643f270d68d6f6
4
- data.tar.gz: 26b8eb9e45b508923bacce4bc06502d3031fc7a8b9c844dfd02775a86191ec3c
3
+ metadata.gz: 7ffee6667b4033ad1987ad90e83c912134bfbc449efbbe1d6c90e3370fd568d1
4
+ data.tar.gz: 5ded113c3c6058688db13120068f35983decfcf772af8f67318a073bf65c7e9a
5
5
  SHA512:
6
- metadata.gz: f32e8ae4585c328c298791628eca4e18e00ac2818bee7aa9c5e1f1f680fd6b60f0a59cc1fd1b4313794d1d7d926dfc195762cf9912e83034d553d248f90f8743
7
- data.tar.gz: '091805806ce97b61bf45f6df58bf5232ce75f65e0d1bcbcdffb0aed949e3e38200b5ea8d9bd600e9c2150e24296af2faf2ac3a99312ec290112bf55770ea38a7'
6
+ metadata.gz: ddbfe113d51f8f89fbc20c950b6de97a9800a8c76dffb04a1ba8e56708a7c3142b1007e1678368df662e9b340ff567d93aeb781656e92a262fa1a417f05f7bb7
7
+ data.tar.gz: ee09e3e0766d396c644ee7be9ef0e88461fec646e57e4e5c58949042d3a87697215f8069781ef1116d12cf0cdda10b62ab609ded409da954f28a85d6489c12f6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,68 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0] - 2025-02-07
4
+
5
+ ### Added
6
+
7
+ - NPM command publish was implemented.
8
+ - Globally created tasks can be excluded.
9
+ - Application method pass for project references was created.
10
+ - Gem command push was implemented.
11
+ - Gem command build was implemented.
12
+ - Gem command exec was implemented.
13
+ - Gem command check was implemented.
14
+ - NPM command install was implemented.
15
+ - NPM command dedupe was implemented.
16
+ - NPM command update was implemented.
17
+ - Double quotes can be used for shell option values.
18
+ - Global build commands can be aliased to alternate commands.
19
+ - Graph can be run with certain projects excluded.
20
+ - Workspace home folder can be set through ENV.
21
+ - Global task command lint was created.
22
+ - NPM command pack was implemented.
23
+ - Git command checkout and reset action commit was implemented.
24
+ - Application method script with pass-through args was created.
25
+ - Project build options can be overwritten with ENV build types.
26
+ - Pip install action editable was implemented.
27
+ - Git command log was implemented.
28
+ - Node package managers can update as depend with NODE_UPDATE.
29
+ - NPM install commands were grouped under package namespace.
30
+ - Node global task command update was created.
31
+
32
+ ### Changed
33
+
34
+ - Global project command options use a private namespace hash.
35
+ - Global git command options use a private namespace hash.
36
+ - Base command options can be constructed from a hash.
37
+ - Git refs and files with complete options were implemented.
38
+ - Git tag action list with complete options was implemented.
39
+ - Git stash per action with complete options was implemented.
40
+ - Git diff with complete options was implemented.
41
+ - Git checkout action path with complete options was implemented.
42
+ - Git reset with complete options was implemented.
43
+ - Git restore with complete options was implemented.
44
+ - Git show with complete options was implemented.
45
+ - Git rev-parse with complete options was implemented.
46
+ - Git rebase with complete options was implemented.
47
+ - Ruby class kwargs opts was converted to optional parameter.
48
+ - Git methods use second parameter for command line options.
49
+ - Project base methods can run multiple commands per task.
50
+ - Project base methods except clean use same run wrapper.
51
+ - Bundle install uses a separate isolated method.
52
+ - Git branch action set negate symbol was inconsistent.
53
+ - Workspace applications have name suffixed ENV settings.
54
+
55
+ ### Fixed
56
+
57
+ - ENV command options did not take precedence to inline options.
58
+
59
+ ## [0.2.3] - 2025-02-05
60
+
61
+ ### Fixed
62
+
63
+ - Project hash options duplicated dash prefix.
64
+ - Pip upgrade did not append package names.
65
+
3
66
  ## [0.2.2] - 2025-01-19
4
67
 
5
68
  ### Fixed
@@ -55,7 +118,7 @@
55
118
  - Gem install and update non-deprecated options are fully complete.
56
119
  - Pip install options are fully complete.
57
120
  - Node command bump action version was implemented.
58
- - Node command add was implemented.
121
+ - Node command add was implemented.
59
122
  - Python command install can use single character options.
60
123
  - Gem install and pristine options are fully complete.
61
124
  - Gem command outdated was implemented.
@@ -169,6 +232,8 @@
169
232
 
170
233
  - Changelog was created.
171
234
 
235
+ [0.3.0]: https://github.com/anpham6/squared/releases/tag/v0.3.0-ruby
236
+ [0.2.3]: https://github.com/anpham6/squared/releases/tag/v0.2.3-ruby
172
237
  [0.2.2]: https://github.com/anpham6/squared/releases/tag/v0.2.2-ruby
173
238
  [0.2.1]: https://github.com/anpham6/squared/releases/tag/v0.2.1-ruby
174
239
  [0.2.0]: https://github.com/anpham6/squared/releases/tag/v0.2.0-ruby
data/README.ruby.md CHANGED
@@ -1,4 +1,4 @@
1
- # squared 0.2
1
+ # squared 0.3
2
2
 
3
3
  * [source](https://github.com/anpham6/squared)
4
4
  * [manifest](https://github.com/anpham6/squared-repo)
@@ -6,10 +6,11 @@
6
6
 
7
7
  ## Version Compatibility
8
8
 
9
- | Date | squared | Min | Max |
10
- | :--------: | ------: | -----: | -----: |
11
- | 2024-12-07 | 0.1.0 | 2.4.0 | 3.3.6 |
12
- | 2025-01-07 | 0.2.0 | 2.4.0 | 3.4.0 |
9
+ | Date | squared | Min | Max | Git |
10
+ | :--------: | ------: | -----: | -----: | -----: |
11
+ | 2024-12-07 | 0.1.0 | 2.4.0 | 3.3.6 | 2.39 |
12
+ | 2025-01-07 | 0.2.0 | 2.4.0 | 3.4.0 | 2.39 |
13
+ | 2025-02-07 | 0.3.0 | 2.4.0 | 3.4.1 | 2.39 |
13
14
 
14
15
  The range chart indicates the latest Ruby tested against at the time of release.
15
16
 
@@ -84,6 +85,10 @@ Workspace::Application
84
85
  .add("e-mc", "emc", copy: { from: "publish", scope: "@e-mc", also: [:pir, "squared-express/"] }, ref: :node) # Node
85
86
  .add("pi-r", "pir", copy: { from: "publish", scope: "@pi-r" }, clean: ["publish/**/*.js", "tmp/"]) # Trailing slash required for directories
86
87
  .add("squared", script: ["build:stage1", "build:stage2"], group: "app") do # Copy target (main)
88
+ # Repo (global)
89
+ as(:run, "build:dev", "dev") # npm run build:dev -> npm run dev
90
+ as(:run, { "build:dev": "dev", "build:prod": "prod" })
91
+
87
92
  add("publish/sqd-cli", "cli", exclude: [:git]) # rake cli:build
88
93
  add("publish/sqd-serve") # rake sqd-serve:build
89
94
  add("publish/sqd-admin", group: "sqd", exclude: [:base])
@@ -97,8 +102,9 @@ Workspace::Application
97
102
  variable_set :depend, false
98
103
  variable_set :clean, ["build/sqd/"]
99
104
  end
105
+ .pass("pull", group: "default") { test? || doc? } # pathname:pull | optparse:pull
100
106
  .style("banner", 255.255) # 256 colors (fg | fg.bg | -0.bg)
101
- .build(default: "build", parallel: ["pull", "fetch", "rebase", "copy", "clean", /^outdated:/]) do |workspace|
107
+ .build(default: "build", parallel: ["pull", "fetch", "rebase", "copy", "clean", /^outdated:/], pass: ['publish']) do |workspace|
102
108
  workspace
103
109
  .enable_aixterm
104
110
  .style({
@@ -143,41 +149,41 @@ The task is only active when the project directory is empty or does not exist.
143
149
  Workspace::Application
144
150
  .new(main: "squared")
145
151
  .git(
146
- "emc": "https://github.com/anpham6/e-mc", # rake emc:clone
147
- "pir": { # rake pir:clone
148
- uri: "https://github.com/anpham6/pi-r", #
149
- options: { #
150
- "origin": "github", # --origin='github'
151
- "recurse-submodules": false, # --no-recurse-submodules
152
- "shallow-exclude": ["v0.0.1", "v0.0.2"] # --shallow-exclude='v0.0.1' --shallow-exclude='v0.0.2'
152
+ "emc": "https://github.com/anpham6/e-mc", # rake emc:clone
153
+ "pir": { # rake pir:clone
154
+ uri: "https://github.com/anpham6/pi-r", #
155
+ options: { #
156
+ "origin": "github", # --origin='github'
157
+ "recurse-submodules": false, # --no-recurse-submodules
158
+ "shallow-exclude": ["v0.0.1", "v0.0.2"] # --shallow-exclude='v0.0.1' --shallow-exclude='v0.0.2'
153
159
  }
154
160
  }
155
161
  )
156
- .git("squared", "/path/to/squared", options: { local: true }) # Relative paths resolve from workspace root
162
+ .git("squared", "/path/to/squared", options: { local: true }) # Relative paths resolve from workspace root
157
163
  .git(
158
164
  {
159
- emc: { uri: "e-mc", options: { "depth": 2 } }, # https://github.com/anpham6/e-mc
160
- pir: "pi-r" # Maps task alias to repository folder
165
+ emc: { uri: "e-mc", options: { "depth": 2 } }, # https://github.com/anpham6/e-mc
166
+ pir: "pi-r" # Maps task alias to repository folder
161
167
  },
162
- base: "https://github.com/anpham6", # Required
163
- repo: ["squared", "android-docs", "chrome-docs"], # https://github.com/anpham6/squared
164
- options: { # Only "repo"
168
+ base: "https://github.com/anpham6", # Required
169
+ repo: ["squared", "android-docs", "chrome-docs"], # https://github.com/anpham6/squared
170
+ options: { # Only "repo"
165
171
  "depth": 1,
166
172
  "quiet": true
167
173
  }
168
174
  )
169
- .with(:node) do # rake clone:node
170
- add("e-mc", "emc") # https://github.com/anpham6/e-mc
171
- add("pi-r", "pir") # https://github.com/anpham6/pi-r
172
- add("squared") # https://github.com/anpham6/squared
175
+ .with(:node) do # rake clone:node
176
+ add("e-mc", "emc") # https://github.com/anpham6/e-mc
177
+ add("pi-r", "pir") # https://github.com/anpham6/pi-r
178
+ add("squared") # https://github.com/anpham6/squared
173
179
  end
174
- .with(:python) do # rake clone:python
180
+ .with(:python) do # rake clone:python
175
181
  add("android-docs")
176
182
  add("chrome-docs")
177
183
  end
178
- .git("https://github.com/anpham6") # Uses already defined root projects
179
- .git("https://github.com/anpham6", ["emc", "pir"]) # Targets any defined project
180
- .build(parallel: ["clone"]) # rake clone + rake clone:sync
184
+ .git("https://github.com/anpham6") # Uses already defined root projects
185
+ .git("https://github.com/anpham6", ["emc", "pir"]) # Targets any defined project
186
+ .build(parallel: ["clone"]) # rake clone + rake clone:sync
181
187
  ```
182
188
 
183
189
  ### Graph
@@ -191,17 +197,21 @@ Workspace::Application
191
197
  add("chrome-docs", "chrome", graph: "android")
192
198
  end
193
199
  .with(:node) do
194
- graph(["build", "copy"], on: { # Overrides "git"
200
+ graph(["build", "copy"], on: { # Overrides "git"
195
201
  first: proc { puts "1" },
196
202
  last: proc { puts "2" }
197
203
  })
204
+ script("build:dev") # npm run build:dev
205
+ # OR
206
+ run([nil, "build:dev", { "PATH" => "~/.bin" }, "--workspace", "--silent"]) # PATH="~/.bin" npm run build:dev --workspace -- --silent
207
+
198
208
  add("e-mc", "emc") do
199
- first("build", "emc:clean", "emc:depend") # rake emc:clean; rake emc:depend; rake emc:build; puts "123";
200
- last("build", out: "123") { |out: nil| puts out } #
201
- error("build") { |err: nil| log.debug err } #
209
+ first("build", "emc:clean", "emc:depend") # rake emc:clean && rake emc:depend && rake emc:build && echo "123"
210
+ last("build", out: "123") { |out: nil| puts out } #
211
+ error("build") { |err: nil| log.debug err } #
202
212
  end
203
213
  add("pi-r", "pir", graph: "emc", first: {
204
- build: proc { puts self.name } # puts "pir"
214
+ build: proc { puts self.name } # puts "pir"
205
215
  })
206
216
  add("squared-express", "express", graph: "pir")
207
217
  add("squared", graph: ["chrome", "express"]) do
@@ -210,11 +220,22 @@ Workspace::Application
210
220
  end
211
221
  end
212
222
  .with(:ruby) do
213
- add("pathname")
223
+ run("gem build") # gem build
224
+ # OR
225
+ run(["gem build", "--force", { "RUBY_VERSION" => "3.4.0" }]) # RUBY_VERSION="3.4.0" gem build --force
226
+ # OR
227
+ run(["gem pristine", ["gem build", "gem cleanup"], nil, "--debug"]) # gem pristine --debug && gem build --debug && gem cleanup --debug
228
+ # OR
229
+ run([ # PATH="~/.bin" GEM_HOME="~/.gems/ruby-3.4.0" (merged)
230
+ ["gem pristine", "--all", { "PATH" => "~/.bin" }, "--silent"], # gem pristine --silent --all
231
+ ["gem build", { strict: true }, { "GEM_HOME" => "~/.gems/ruby-3.4.0" }] # gem build --strict
232
+ ])
233
+
234
+ add("pathname", test: ["rake test", { jobs: ENV["RAKE_JOBS"] }]) # rake test --jobs 4
214
235
  add("fileutils", graph: "pathname")
215
- add("optparse")
236
+ add("optparse", run: "gem build", env: { "PATH" => "~/.bin" }, opts: "-v") # PATH="~/.bin" gem build -v
216
237
  add("rake", graph: ["fileutils", "optparse"])
217
- banner(command: false) # Always hide banner
238
+ banner(command: false) # Always hide banner
218
239
  end
219
240
  .build
220
241
  ```
@@ -229,6 +250,9 @@ rake graph:node # same
229
250
  rake rake:graph # pathname + fileutils + optparse + rake
230
251
  rake graph:ruby # same
231
252
  rake graph # graph:node + graph:ruby
253
+
254
+ rake squared:graph:run[express,pir] # emc + pir + express + squared
255
+ rake squared:graph:run[node,-emc] # pir + express + squared
232
256
  ```
233
257
 
234
258
  ### Batch
@@ -288,10 +312,12 @@ rake squared:outdated:workspace # cli + sqd-serve + sqd-admin
288
312
  Task:
289
313
 
290
314
  * run
315
+ * script
291
316
  * depend
292
317
  * graph
293
- * test
294
318
  * doc
319
+ * lint
320
+ * test
295
321
  * clean
296
322
 
297
323
  Non-task:
@@ -332,51 +358,107 @@ Common::PATH.merge!({
332
358
  ### Build
333
359
 
334
360
  ```ruby
335
- # :env :run :opts
336
- # LD_LIBRARY_PATH="path/to/lib" CFLAGS="-Wall" gcc a.c -o a.o -c
337
- BUILD_${NAME} # gcc a.c -o a.o
338
- BUILD_OPTS_${NAME} # -c
339
- BUILD_ENV_${NAME} # {"LD_LIBRARY_PATH":"path/to/lib","CFLAGS":"-Wall"} (hash/json)
340
-
341
- # :env :opts :script
342
- # NODE_ENV="production" NO_COLOR="1" npm run --loglevel=error --workspaces=false build:dev
343
- BUILD_${NAME} # build:dev
344
- BUILD_OPTS_${NAME} # --loglevel=error --workspaces=false
345
- BUILD_ENV_${NAME} # {"NODE_ENV":"production","NO_COLOR":"1"} (hash/json)
346
- BUILD_DEV_${NAME} # pattern,0,1 (:dev)
347
- BUILD_PROD_${NAME} # pattern,0,1 (:prod)
348
-
349
- BUILD_${NAME}=0 # skip project
361
+ Workspace::Application
362
+ .new
363
+ .add("squared", run: "gcc a.c -o a.o", opts: { __debug__: { g: true, O2: true, c: nil }, c: true, j: 4 }) # gcc a.c -o a.o -c -j4
364
+
365
+ BUILD_TYPE # global
366
+
367
+ # :env :run :opts :type
368
+ # LD_LIBRARY_PATH="path/to/lib" CFLAGS="-Wall" gcc a.c -o a.o -g -O2
369
+ BUILD_${NAME} # gcc a.c -o a.o
370
+ BUILD_${NAME}_OPTS # -g
371
+ BUILD_${NAME}_ENV # {"LD_LIBRARY_PATH":"path/to/lib","CFLAGS":"-Wall"} (hash/json)
372
+ BUILD_${NAME}_TYPE # debug
373
+
374
+ # :env :opts :script :args
375
+ # NODE_ENV="production" NO_COLOR="1" npm run --loglevel=error --workspaces=false build:dev -- --quiet
376
+ BUILD_${NAME} # build:dev
377
+ BUILD_${NAME}_OPTS # --loglevel=error --workspaces=false
378
+ BUILD_${NAME}_ENV # {"NODE_ENV":"production","NO_COLOR":"1"} (hash/json)
379
+ BUILD_${NAME}_DEV # pattern,0,1 (:dev)
380
+ BUILD_${NAME}_PROD # pattern,0,1 (:prod)
381
+ SCRIPT_${NAME}_OPTS # --quiet
382
+
383
+ BUILD_${NAME}=0 # skip project
350
384
  ```
351
385
 
352
- These options also support the project specific suffix `${NAME}`. (e.g. LOG_FILE_SQUARED)
386
+ ### Graph
387
+
388
+ ```ruby
389
+ GRAPH_${NAME} # depend,build => squared:depend + squared:build
390
+ GRAPH_${NAME}_PASS # -emc,pir,express => pir + express
391
+ ```
353
392
 
354
393
  ### Logger
355
394
 
395
+ These global options also can target the project suffix `${NAME}`. (e.g. LOG_FILE_EMC)
396
+
356
397
  ```ruby
357
- LOG_FILE # %Y-%m-%d.log
398
+ LOG_FILE # %Y-%m-%d.log
358
399
  # OR
359
- LOG_AUTO # year,y,month,m,day,d,1
400
+ LOG_AUTO # year,y,month,m,day,d,1
360
401
  # Optional
361
- LOG_DIR # exist?
362
- LOG_LEVEL # See gem "logger"
363
- LOG_COLUMNS # terminal width (default: 80)
402
+ LOG_DIR # exist?
403
+ LOG_LEVEL # See gem "logger"
404
+ LOG_COLUMNS # terminal width (default: 80)
364
405
  ```
365
406
 
366
407
  ### Repo
367
408
 
409
+ These global options also can target the application main suffix `${NAME}`. (e.g. REPO_ROOT_SQUARED)
410
+
411
+ ```ruby
412
+ REPO_ROOT # parent dir
413
+ REPO_HOME # project dir (main)
414
+ REPO_BUILD # run,script
415
+ REPO_GROUP # string
416
+ REPO_REF # e.g. ruby,node
417
+ REPO_DEV # pattern,0,1
418
+ REPO_PROD # pattern,0,1
419
+ REPO_WARN # 0,1
420
+ REPO_SYNC # 0,1
421
+ REPO_MANIFEST # e.g. latest,nightly,prod
422
+ REPO_TIMEOUT # confirm dialog (seconds)
423
+ ```
424
+
425
+ ## Git
426
+
427
+ Most project classes will inherit from `Git` which enables these tasks:
428
+
429
+ | Task | Git | Command |
430
+ | :--------- | :--------------- | :-------------------------------------------- |
431
+ | branch | branch | create set delete move copy list edit current |
432
+ | checkout | checkout | commit branch track detach path |
433
+ | commit | commit | add all amend amend-orig |
434
+ | diff | diff | head cached branch files between contain |
435
+ | fetch | fetch | origin remote |
436
+ | files | ls-files | cached modified deleted others ignored |
437
+ | pull | pull | origin remote |
438
+ | rebase | rebase | branch onto send |
439
+ | refs | ls-remote --refs | heads tags remote |
440
+ | reset | reset | commit index patch mode |
441
+ | restore | restore | source worktree staged overlay |
442
+ | rev | rev | commit branch output parseopt |
443
+ | show | show | format oneline |
444
+ | stash | stash | push pop apply drop list |
445
+ | tag | tag | add delete list |
446
+
447
+ You can disable all of them at once using the `exclude` property.
448
+
368
449
  ```ruby
369
- REPO_ROOT # parent dir
370
- REPO_HOME # project dir (main)
371
- REPO_BUILD # run,script
372
- REPO_GROUP # string
373
- REPO_REF # e.g. ruby,node
374
- REPO_DEV # pattern,0,1
375
- REPO_PROD # pattern,0,1
376
- REPO_WARN # 0,1
377
- REPO_SYNC # 0,1
378
- REPO_MANIFEST # e.g. latest,nightly,prod
379
- REPO_TIMEOUT # confirm dialog (seconds)
450
+ Workspace::Application
451
+ .new
452
+ .add("squared", exclude: :git)
453
+ ```
454
+
455
+ You can disable one or more of them using the `pass` property as a *string*.
456
+
457
+ ```ruby
458
+ Workspace::Application
459
+ .new
460
+ .add("squared", pass: ["pull"], ref: :node)
461
+ .pass("pull", ref: :node) { read_packagemanager(:private) }
380
462
  ```
381
463
 
382
464
  ## LICENSE
@@ -6,10 +6,12 @@ module Squared
6
6
  ARG = {
7
7
  PIPE: 1,
8
8
  OUT: nil,
9
- VERBOSE: nil,
10
9
  FAIL: false,
10
+ HOME: nil,
11
11
  COMMON: true,
12
+ VERBOSE: nil,
12
13
  BANNER: true,
14
+ QUOTE: "'",
13
15
  SPACE: ' => ',
14
16
  GRAPH: ['│', '─', '├', '└', '┬'],
15
17
  VIEW: 'view',
@@ -9,7 +9,7 @@ module Squared
9
9
  extend Forwardable
10
10
 
11
11
  def self.to_s
12
- super.match(/[^:]+\z/)[0]
12
+ super[/[^:]+\z/, 0]
13
13
  end
14
14
 
15
15
  def_delegators :@data, :+, :each, :each_with_index, :entries, :to_a, :include?
@@ -31,7 +31,7 @@ module Squared
31
31
 
32
32
  class JoinSet < Set
33
33
  def self.to_s
34
- super.match(/[^:]+\z/)[0]
34
+ super[/[^:]+\z/, 0]
35
35
  end
36
36
 
37
37
  attr_reader :delim
@@ -41,8 +41,33 @@ module Squared
41
41
  @delim = delim
42
42
  end
43
43
 
44
+ def last(val, pat)
45
+ (@last ||= []).push([val, pat, $1]) if val =~ pat
46
+ self << val
47
+ end
48
+
44
49
  def pass(&blk)
45
50
  ret = to_a.map!(&:to_s).reject(&:empty?)
51
+ @last&.each do |val, pat, key|
52
+ i = []
53
+ j = nil
54
+ ret.each_with_index do |opt, index|
55
+ if opt == val
56
+ j = index
57
+ elsif j && opt =~ pat && $1 == key
58
+ i << index
59
+ end
60
+ end
61
+ next unless j && !i.empty?
62
+
63
+ val = ret[j]
64
+ cur = j
65
+ i.each do |k|
66
+ ret[cur] = ret[k]
67
+ cur = k
68
+ end
69
+ ret[i.last] = val
70
+ end
46
71
  block_given? ? ret.reject(&blk) : ret
47
72
  end
48
73
 
@@ -66,7 +66,7 @@ module Squared
66
66
  f, b = type.to_s.split('.')
67
67
  s = wrap.(s, ['38', '5', f]) if f[0] != '-' && f.to_i <= 255
68
68
  if b
69
- b = b[0..2]
69
+ b = b[0, 3]
70
70
  s = wrap.(s, ['48', '5', b]) unless b.to_i > 255
71
71
  end
72
72
  else
@@ -117,7 +117,7 @@ module Squared
117
117
  elsif val >= 0 && val <= 256
118
118
  ret << val
119
119
  elsif val < 0 && (b = val.to_s.split('.')[1])
120
- b = b[0..2]
120
+ b = b[0, 3]
121
121
  ret << "-0.#{b}".to_f unless b.to_i > 255
122
122
  end
123
123
  end
@@ -189,7 +189,7 @@ module Squared
189
189
  begin
190
190
  File.open(pipe, 'a') do |f|
191
191
  br = File::SEPARATOR == '\\' ? "\r\n" : "\n"
192
- args.flatten.each { |val| f.write("#{strip_style(val.chomp)}#{br}") }
192
+ args.flatten.each { |val| f.write(strip_style(val.chomp) + br) }
193
193
  end
194
194
  return
195
195
  rescue StandardError
@@ -16,7 +16,7 @@ module Squared
16
16
  if data[4] == data[6]
17
17
  data[4] ? val : join.(data[5])
18
18
  else
19
- join.("#{data[4]}#{data[5]}#{data[6]}")
19
+ join.(data[4] + data[5] + data[6])
20
20
  end
21
21
  elsif Rake::Win32.windows?
22
22
  quote ? shell_quote(val, force: force) : val
@@ -29,7 +29,7 @@ module Squared
29
29
  val = val.to_s
30
30
  return val if (!force && !val.include?(' ')) || val.match?(/(?:^|\S=|[^=]\s+)(["']).+\1\z/m)
31
31
 
32
- Rake::Win32.windows? ? "\"#{double_quote(val)}\"" : "'#{single_quote(val)}'"
32
+ Rake::Win32.windows? || ARG[:QUOTE] == '"' ? "\"#{double_quote(val)}\"" : "'#{single_quote(val)}'"
33
33
  end
34
34
 
35
35
  def shell_split(val, quote: false, join: nil)
@@ -39,13 +39,18 @@ module Squared
39
39
  val.join(join.is_a?(::String) ? join : ' ')
40
40
  end
41
41
 
42
- def shell_option(flag, val = nil, escape: true, quote: true)
43
- a, b = flag.size == 1 ? ['-', ' '] : ['--', '=']
42
+ def shell_option(flag, val = nil, escape: true, quote: true, force: true)
43
+ flag = flag.to_s
44
+ if flag[0] == '-'
45
+ b = flag[1] == '-' ? '=' : ' '
46
+ else
47
+ a, b = flag.size == 1 ? ['-', ' '] : ['--', '=']
48
+ end
44
49
  "#{a}#{flag}#{if val
45
50
  "#{b}#{if escape
46
51
  shell_escape(val, quote: quote)
47
52
  else
48
- quote ? shell_quote(val) : val
53
+ quote ? shell_quote(val, force: force) : val
49
54
  end}"
50
55
  end}"
51
56
  end
@@ -61,7 +66,7 @@ module Squared
61
66
  end
62
67
 
63
68
  def basic_option(flag, val)
64
- shell_option(flag, val, escape: false, quote: false)
69
+ shell_option(flag, val, escape: false, force: false)
65
70
  end
66
71
 
67
72
  def single_quote(val)
@@ -35,33 +35,44 @@ module Squared
35
35
  end
36
36
  end
37
37
 
38
- def env(key, default = nil, suffix: @envname, equals: nil, ignore: nil)
39
- ret = env_value(key, suffix: suffix)
38
+ def env(key, default = nil, suffix: nil, strict: false, equals: nil, ignore: nil)
39
+ ret = env_value(key, suffix: suffix, strict: strict)
40
40
  return ret == equals.to_s unless equals.nil?
41
41
 
42
42
  ret.empty? || (ignore && as_a(ignore).any? { |val| ret == val.to_s }) ? default : ret
43
43
  end
44
44
 
45
- def env_value(key, default = '', suffix: nil)
46
- suffix && (ret = ENV["#{key}_#{suffix}"]) ? ret : ENV.fetch(key, default)
45
+ def env_value(key, default = '', suffix: nil, strict: false)
46
+ if suffix
47
+ if (ret = ENV["#{key}#{@envname ? "_#{@envname}" : ''}_#{suffix}"])
48
+ return ret
49
+ elsif strict
50
+ return default
51
+ end
52
+ end
53
+ if @envname
54
+ return ret if (ret = ENV["#{key}_#{@envname}"])
55
+ return default if strict
56
+ end
57
+ ENV.fetch(key, default)
47
58
  end
48
59
 
49
- def env_bool(key, default = false, suffix: nil)
60
+ def env_bool(key, default = false, suffix: nil, strict: false, index: false)
50
61
  if key.is_a?(::String)
51
- case env_value(key, suffix: suffix)
62
+ case (val = env_value(key, suffix: suffix, strict: strict))
52
63
  when ''
53
64
  default
54
65
  when '0', 'false'
55
66
  false
56
67
  else
57
- true
68
+ index && val.to_i > 0 ? val.to_i : true
58
69
  end
59
70
  else
60
71
  key.nil? ? default : key
61
72
  end
62
73
  end
63
74
 
64
- def env_pipe(key, default = 1, suffix: nil, root: nil)
75
+ def env_pipe(key, default = 1, suffix: nil, strict: false, root: nil)
65
76
  if default.is_a?(::String)
66
77
  begin
67
78
  default = (root ? root.join(default) : Pathname.new(default)).realdirpath
@@ -72,7 +83,7 @@ module Squared
72
83
  end
73
84
  case key
74
85
  when ::String
75
- case (ret = env_value(key, suffix: suffix))
86
+ case (ret = env_value(key, suffix: suffix, strict: strict))
76
87
  when '0', '1', '2'
77
88
  return ret.to_i
78
89
  end
@@ -82,8 +93,8 @@ module Squared
82
93
  default
83
94
  end
84
95
 
85
- def env_match(key, default = nil, suffix: nil, options: 0, timeout: nil)
86
- case (ret = env_value(key, suffix: suffix))
96
+ def env_match(key, default = nil, suffix: nil, strict: false, options: 0, timeout: nil)
97
+ case (val = env_value(key, suffix: suffix, strict: strict))
87
98
  when ''
88
99
  default
89
100
  when '0'
@@ -91,7 +102,7 @@ module Squared
91
102
  when '1'
92
103
  true
93
104
  else
94
- Regexp.new(ret, options, timeout: timeout)
105
+ Regexp.new(val, options, timeout: timeout)
95
106
  end
96
107
  end
97
108
  end