squared 0.1.5 → 0.1.7

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: a3ad5f0881e8642ae1d57fccbba6a1fdc3ff555b6efcd7eb2989a5675ff5bcd3
4
- data.tar.gz: 426a514ca02ddf64fa2009ad165d0bf9e0053905c58643c7398e7c1d17630fcc
3
+ metadata.gz: a84fd3fef43628c438131d98c9ac058b2511a7a7f0edab355ae534137a612d1d
4
+ data.tar.gz: 46e0925a6e7d854d71602aee88d54c2efff7e7ff782d847fd85e95759bad3ffb
5
5
  SHA512:
6
- metadata.gz: af9e72989be1dbbf614f8c7dd5989a0081775e4433ad280a4bae600660e56bd1ba20aa6a3f33ad367b349a209227be5b823c4e496367533260c1a86ae3a6dd6c
7
- data.tar.gz: d0dd6f39e8b8f8834768c93ab26718618d0d0023f99a242321f6925bee9fcc782ebbfd86a698bdcebe17fb1deb763c79d46d77001d55a13b24ddc391beb0a3c8
6
+ metadata.gz: e90a44a3914f551b4567d2013882ce362dfdc43b44bb157cb24fb2b6171cb64c46dbbb680ba7fcc17fd32f76d0e8d82bfa5ddc411eb00de5524ab5407135d413
7
+ data.tar.gz: 993f3899bf89ed18f8b89ddda7019c33484b76d2a770a72b8280fa898af6a7caecceafe862de7854236c9e52ddb7c2100cd9e388b8afb4dd3d0f4427647f15ad
data/CHANGELOG.md CHANGED
@@ -1,6 +1,26 @@
1
1
  # Changelog
2
2
 
3
- ## [0.1.5] - 2024-02-25
3
+ ## [0.1.7] - 2025-04-27
4
+
5
+ ### Fixed
6
+
7
+ - Project directory context method option pass was inverted.
8
+ - Shell options with spaces and without quotes were not escaped.
9
+ - Git task status did not display branch information.
10
+ - Ruby copy method argument include was ignored when used directly.
11
+ - Git commit could not push branch without same name as remote.
12
+
13
+ ## [0.1.6] - 2025-04-17
14
+
15
+ ### Fixed
16
+
17
+ - Log messages were concatenated without separator.
18
+ - Regexp "o" modifier was not used properly.
19
+ - Rake did not run individual project Rakefile.
20
+ - User-defined program paths were not reduced to bare name.
21
+ - Project path validation did not include separator.
22
+
23
+ ## [0.1.5] - 2025-02-25
4
24
 
5
25
  ### Fixed
6
26
 
@@ -10,7 +30,7 @@
10
30
  - Logger is not initialized when using only base class.
11
31
  - Merging ENV build options were double escaped.
12
32
 
13
- ## [0.1.4] - 2024-02-05
33
+ ## [0.1.4] - 2025-02-05
14
34
 
15
35
  ### Fixed
16
36
 
@@ -19,7 +39,7 @@
19
39
  - Git command refs did not include ref option.
20
40
  - Pip upgrade did not append package names.
21
41
 
22
- ## [0.1.3] - 2024-01-02
42
+ ## [0.1.3] - 2025-01-02
23
43
 
24
44
  ### Fixed
25
45
 
@@ -98,6 +118,8 @@
98
118
 
99
119
  - Changelog was created.
100
120
 
121
+ [0.1.7]: https://github.com/anpham6/squared/releases/tag/v0.1.7-ruby
122
+ [0.1.6]: https://github.com/anpham6/squared/releases/tag/v0.1.6-ruby
101
123
  [0.1.5]: https://github.com/anpham6/squared/releases/tag/v0.1.5-ruby
102
124
  [0.1.4]: https://github.com/anpham6/squared/releases/tag/v0.1.4-ruby
103
125
  [0.1.3]: https://github.com/anpham6/squared/releases/tag/v0.1.3-ruby
@@ -53,7 +53,7 @@ module Squared
53
53
  end
54
54
  wrap = ->(s, n) { "\x1B[#{n.join(';')}m#{s}\x1B[0m" }
55
55
  code = []
56
- args.concat(as_a(styles)).each_with_index do |type, i|
56
+ args.concat(as_a(styles)).flatten.each_with_index do |type, i|
57
57
  next unless type
58
58
 
59
59
  if index == -1
@@ -114,7 +114,7 @@ module Squared
114
114
  if !val.is_a?(::Numeric)
115
115
  val = val.to_sym
116
116
  ret << val if colors.key?(val) || TEXT_STYLE.include?(val)
117
- elsif val >= 0 && val <= 256
117
+ elsif val.between?(0, 256)
118
118
  ret << val
119
119
  elsif val < 0 && (b = val.to_s.split('.')[1])
120
120
  b = b[0..2]
@@ -174,12 +174,8 @@ module Squared
174
174
  emphasize(args, title: title + (subject ? " #{subject}" : ''), sub: sub)
175
175
  else
176
176
  msg = [log_title(level, color: color)]
177
- if subject
178
- msg << (color ? sub_style(subject, :underline) : subject)
179
- else
180
- msg += args
181
- args.clear
182
- end
177
+ msg << (color ? sub_style(subject, :underline) : subject) if subject
178
+ msg << args.shift if msg.size == 1
183
179
  message(msg.join(' '), *args, hint: hint)
184
180
  end
185
181
  end
@@ -278,6 +274,10 @@ module Squared
278
274
  val.gsub(/\x1B\[(\d+;?)+m/, '')
279
275
  end
280
276
 
277
+ def stripext(val)
278
+ File.basename(val, File.extname(val))
279
+ end
280
+
281
281
  def raise_error(*args, hint: nil, kind: ArgumentError)
282
282
  raise kind, message(*args, hint: hint, empty: true)
283
283
  end
@@ -21,7 +21,7 @@ module Squared
21
21
  return false
22
22
  end
23
23
  attempts -= 1
24
- exit 1 unless attempts >= 0
24
+ exit 1 unless attempts > 0
25
25
  end
26
26
  rescue Interrupt
27
27
  puts
@@ -10,7 +10,7 @@ module Squared
10
10
 
11
11
  def shell_escape(val, quote: false, force: false)
12
12
  if (data = /\A(--?[^= ]+)((=|\s+)(["'])?(.+?)(["'])?)?\z/m.match(val = val.to_s))
13
- return val if !data[2] || (!data[4] && data[5] =~ /\s/)
13
+ return val if !data[2] || (!data[4] && !data[5].match?(/\s/))
14
14
 
15
15
  join = ->(opt) { data[1] + data[3] + shell_quote(opt) }
16
16
  if data[4] == data[6]
@@ -21,7 +21,7 @@ module Squared
21
21
  elsif Rake::Win32.windows?
22
22
  quote ? shell_quote(val, force: force) : val
23
23
  else
24
- Shellwords.escape(val)
24
+ val.empty? ? '' : Shellwords.escape(val)
25
25
  end
26
26
  end
27
27
 
@@ -65,7 +65,7 @@ module Squared
65
65
  end
66
66
 
67
67
  def split_escape(val, char: ',')
68
- val.split(/\s*(?<!\\)#{char}\s*/o)
68
+ val.split(/\s*(?<!\\)#{char}\s*/)
69
69
  end
70
70
  end
71
71
  end
@@ -77,7 +77,7 @@ module Squared
77
77
  return ret.to_i
78
78
  end
79
79
  when ::Numeric
80
- return key if key >= 0 && key <= 2
80
+ return key if key.between?(0, 2)
81
81
  end
82
82
  default
83
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Squared
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.7'
5
5
  end
@@ -679,7 +679,8 @@ module Squared
679
679
  end
680
680
 
681
681
  def session(*cmd, prefix: cmd.first)
682
- if (val = env("#{prefix.upcase}_OPTIONS"))
682
+ prefix = stripext(prefix.to_s).upcase
683
+ if (val = env("#{prefix}_OPTIONS"))
683
684
  split_escape(val).each { |opt| cmd << fill_option(opt) }
684
685
  end
685
686
  @session = JoinSet.new(cmd)
@@ -696,7 +697,7 @@ module Squared
696
697
  def option(*args, prefix: @session&.first, **kwargs)
697
698
  if prefix
698
699
  args.each do |val|
699
- ret = env("#{prefix}_#{val.gsub(/\W/, '_')}".upcase, **kwargs)
700
+ ret = env("#{stripext(prefix)}_#{val.gsub(/\W/, '_')}".upcase, **kwargs)
700
701
  return ret if ret
701
702
  end
702
703
  end
@@ -869,7 +870,7 @@ module Squared
869
870
 
870
871
  def guard_params(action, flag, args: nil, key: nil, pat: nil)
871
872
  if args && key
872
- val = args[key]
873
+ val = args.fetch(key, nil)
873
874
  return val unless val.nil? || (pat && !val.match?(pat))
874
875
 
875
876
  @session = nil
@@ -921,7 +922,7 @@ module Squared
921
922
  def pwd_set(done = nil, pass: false, &blk)
922
923
  pwd = Pathname.pwd
923
924
  if block_given?
924
- if path == pwd || pass == true || (pass.is_a?(String) && semscan(pass).join >= RUBY_VERSION)
925
+ if path == pwd || pass == true || (pass.is_a?(String) && semscan(pass).join <= RUBY_VERSION)
925
926
  ret = instance_eval(&blk)
926
927
  else
927
928
  Dir.chdir(path)
@@ -974,7 +975,8 @@ module Squared
974
975
  end
975
976
 
976
977
  def projectpath?(val)
977
- Pathname.new(val).absolute? ? val.to_s.start_with?(File.join(path, '')) : !val.to_s.start_with?('..')
978
+ val = Pathname.new(val).cleanpath
979
+ val.absolute? ? val.to_s.start_with?(File.join(path, '')) : !val.to_s.start_with?(File.join('..', ''))
978
980
  end
979
981
 
980
982
  def semmajor?(cur, want)
@@ -295,6 +295,7 @@ module Squared
295
295
 
296
296
  def status
297
297
  cmd = git_session 'status', option('long') ? '--long' : '--short'
298
+ cmd << '--branch' if option('branch')
298
299
  if (val = option('ignore-submodules', ignore: false))
299
300
  cmd << shell_option('ignore-submodules', case val
300
301
  when '0', 'none'
@@ -465,41 +466,29 @@ module Squared
465
466
  raise_error('commit', 'pathspec', hint: 'missing') if (files = projectmap(files)).empty?
466
467
  "-- #{files.join(' ')}"
467
468
  end
468
- origin = nil
469
+ format = '%(if)%(HEAD)%(then)%(refname:short)...%(upstream:short)...%(upstream:track)%(end)'
469
470
  branch = nil
470
- upstream = false
471
- source('git fetch --no-tags --quiet', io: true, banner: false)
472
- source('git branch -vv --list', io: true, banner: false).first.each do |val|
473
- next unless (data = /\A\*\s(\S+)\s+(\h+)(?:\s\[(.+?)(?=\]\s)\])?\s/.match(val))
474
-
475
- branch = data[1]
476
- sha = data[2]
477
- if !data[3]
478
- unless (origin = option('repository', prefix: 'git', ignore: false))
479
- out = source('git log -n1 --format=%h%d', io: true, stdout: true, banner: false).first
480
- if (data = /\A#{sha} \(HEAD -> #{Regexp.escape(branch)}, (.+?)\)\z/.match(out))
481
- split_escape(data[1]).each do |val|
482
- next unless val.end_with?("/#{branch}")
483
-
484
- origin = val[0..val.size - branch.size - 2]
485
- break
486
- end
487
- end
488
- end
489
- upstream = !origin.nil?
490
- elsif (data = Regexp.new("\\A(.+)/#{Regexp.escape(branch)}\\z").match(data[3]))
491
- origin = data[1]
471
+ origin = nil
472
+ source('git fetch --no-tags --quiet', io: true, banner: false, stdout: true)
473
+ source("git for-each-ref --format=\"#{format}\" refs/heads", io: true, banner: false).first.each do |line|
474
+ next if (line = line.chomp).empty?
475
+
476
+ branch, origin, hint = line.split('...')
477
+ if hint && !hint.match?(/^\[(\D+0,\D+0)\]$/)
478
+ raise_error('work tree is not usable', hint: hint[1..-2])
479
+ elsif origin.empty?
480
+ return nil if pass
481
+
482
+ raise_error('no remote upstream', hint: branch)
492
483
  end
493
484
  break
494
485
  end
495
- raise_error('commit', 'work tree is not usable') unless origin && branch
486
+ i = origin.index('/')
487
+ branch = "#{branch}:#{origin[i + 1..-1]}" unless origin.end_with?("/#{branch}")
488
+ origin = origin[0..i - 1]
496
489
  cmd = git_session 'commit'
497
490
  cmd << '--dry-run' if option('dry-run')
498
- if amend
499
- cmd << '--amend'
500
- else
501
- cmd.delete('--amend')
502
- end
491
+ cmd << '--amend' if amend
503
492
  if message
504
493
  append_message message
505
494
  elsif flag == :'amend-orig' || option('no-edit')
@@ -507,13 +496,9 @@ module Squared
507
496
  end
508
497
  a = ['git add --verbose']
509
498
  b = ['git push']
510
- b << '--set-upstream' if upstream
511
- if dry_run?
512
- a << '--dry-run'
513
- b << '--dry-run'
514
- end
499
+ b << '--dry-run' if dry_run?
515
500
  a << pathspec
516
- b << '--force' if amend
501
+ b << '--force-with-lease' if amend
517
502
  b << origin << branch
518
503
  puts if pass
519
504
  source a.join(' ')
@@ -207,13 +207,15 @@ module Squared
207
207
  end
208
208
  end
209
209
 
210
- def copy(from: 'lib', include: nil, exclude: nil, into: @gemdir, override: false)
210
+ def copy(from: 'lib', into: @gemdir, override: false, **kwargs)
211
+ glob = kwargs[:include]
212
+ pass = kwargs[:exclude]
211
213
  if @copy && !override
212
214
  return super if runnable?(@copy)
213
215
 
214
216
  from = @copy[:from] if @copy.key?(:from)
215
217
  glob = @copy[:include] if @copy.key?(:include)
216
- exclude = @copy[:exclude] if @copy.key?(:exclude)
218
+ pass = @copy[:exclude] if @copy.key?(:exclude)
217
219
  into = @copy[:into] if @copy.key?(:into)
218
220
  end
219
221
  return unless into
@@ -224,9 +226,9 @@ module Squared
224
226
  as_a(from).each_with_index do |val, i|
225
227
  a = basepath(val)
226
228
  b = dest.join(val)
227
- c = glob[i] || glob[0]
229
+ c = glob[i] || glob.first
228
230
  log.info "cp #{a.join(c)} #{b}"
229
- copy_d(a, b, glob: c, pass: exclude, verbose: verbose)
231
+ copy_d(a, b, glob: c, pass: pass, verbose: verbose)
230
232
  end
231
233
  end
232
234
 
@@ -364,11 +366,11 @@ module Squared
364
366
  end
365
367
 
366
368
  def rake(*cmd)
367
- rakefile = shell_option('rakefile', Rake.application.rakefile, quote: true, escape: false)
369
+ file = shell_option('rakefile', rakefile, quote: true, escape: false)
368
370
  if cmd.empty?
369
- run_s("rake #{rakefile}", chdir: workspace.pwd)
371
+ run_s("rake #{file}", chdir: workspace.pwd)
370
372
  else
371
- run_s(*cmd.map { |val| "rake #{rakefile} #{val}" }, chdir: workspace.pwd, banner: false)
373
+ run_s(*cmd.map { |val| "rake #{file} #{val}" }, chdir: workspace.pwd, banner: false)
372
374
  end
373
375
  end
374
376
 
@@ -3,8 +3,6 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  module Repo
6
- include Common::Format
7
-
8
6
  class << self
9
7
  def read_manifest(path)
10
8
  require 'rexml/document'
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 2025-02-25 00:00:00.000000000 Z
11
+ date: 2025-04-28 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: rake
@@ -106,6 +107,7 @@ metadata:
106
107
  homepage_uri: https://github.com/anpham6/squared
107
108
  source_code_uri: https://github.com/anpham6/squared
108
109
  documentation_uri: https://squared.readthedocs.io
110
+ post_install_message:
109
111
  rdoc_options: []
110
112
  require_paths:
111
113
  - lib
@@ -120,7 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  - !ruby/object:Gem::Version
121
123
  version: '0'
122
124
  requirements: []
123
- rubygems_version: 3.6.2
125
+ rubygems_version: 3.3.27
126
+ signing_key:
124
127
  specification_version: 4
125
128
  summary: Rake task generator for managing multi-language workspaces.
126
129
  test_files: []