squared 0.4.6 → 0.4.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.
@@ -0,0 +1,197 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Squared
6
+ module Workspace
7
+ module Project
8
+ module Support
9
+ class OptionPartition
10
+ include Common::Shell
11
+ extend Forwardable
12
+
13
+ class << self
14
+ include Common::Format
15
+ include Shell
16
+ include Prompt
17
+
18
+ def append(target, *args, delim: false, escape: false, quote: true)
19
+ return if args.empty?
20
+
21
+ target << '--' if delim && !target.include?('--')
22
+ ret = args.flatten.map { |val| escape ? shell_escape(val, quote: quote) : shell_quote(val) }
23
+ if target.is_a?(Set)
24
+ target.merge(ret)
25
+ else
26
+ target.concat(ret)
27
+ end
28
+ ret
29
+ end
30
+
31
+ def clear(target, opts, pass: true, styles: nil, **kwargs)
32
+ return if opts.empty?
33
+
34
+ kwargs[:subject] ||= stripext(target.first)
35
+ kwargs[:hint] ||= 'unrecognized'
36
+ append(target, opts, delim: true) if kwargs.delete(:append)
37
+ warn log_message(Logger::WARN, opts.join(', '), pass: true, **kwargs)
38
+ return if pass || confirm("Run? [#{sub_style(target, styles: styles)}] [y/N] ", 'N', timeout: 30)
39
+
40
+ raise_error 'user cancelled'
41
+ end
42
+
43
+ def arg?(target, *args, value: false)
44
+ r, s = args.partition { |val| val.is_a?(Regexp) }
45
+ unless s.empty?
46
+ s.map! { |val| Regexp.escape(shell_option(val)) }
47
+ r << /\A(?:#{s.join('|')})#{value ? '[ =].' : '(?: |=|\z)'}/
48
+ end
49
+ target.any? { |opt| r.any? { |val| opt.match?(val) } }
50
+ end
51
+ end
52
+
53
+ attr_reader :target, :extras, :found, :errors, :values, :project, :path
54
+
55
+ def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
56
+ :merge, :delete, :delete?, :grep, :inspect, :to_a, :to_s
57
+ def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :first, :last, :shift, :pop, :push,
58
+ :join, :map, :map!, :dup, :size
59
+
60
+ def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
61
+ @target = target.is_a?(Set) ? target : Set.new(target)
62
+ @project = project
63
+ @path = path || project&.path
64
+ @errors = []
65
+ @found = []
66
+ parse(list, opts, **kwargs, &blk)
67
+ end
68
+
69
+ def parse(list, opts = extras, no: nil, single: nil, args: false, first: false, pass: ['='], &blk)
70
+ @extras = []
71
+ @values = []
72
+ bare = []
73
+ e = []
74
+ b = []
75
+ m = []
76
+ p = []
77
+ q = []
78
+ qq = []
79
+ i = []
80
+ f = []
81
+ si = []
82
+ list.map do |val|
83
+ x, y = val.split('|')
84
+ if y
85
+ if (n = val.index('='))
86
+ x += val[n..-1]
87
+ end
88
+ [x, y]
89
+ else
90
+ x
91
+ end
92
+ end
93
+ .flatten
94
+ .each do |val|
95
+ if (n = val.index('='))
96
+ flag = val[0, n]
97
+ case val[n + 1]
98
+ when 'e'
99
+ e << flag
100
+ when 'b'
101
+ b << flag
102
+ when 'm'
103
+ m << flag
104
+ when 'q'
105
+ qq << flag if val[n + 2] == 'q'
106
+ q << flag
107
+ when 'p'
108
+ p << flag
109
+ when 'i'
110
+ i << flag
111
+ when 'f'
112
+ f << flag
113
+ when 'n'
114
+ si << flag
115
+ when 'v'
116
+ @values << Regexp.escape(flag)
117
+ else
118
+ next
119
+ end
120
+ bare << flag if val.end_with?('?')
121
+ else
122
+ bare << val
123
+ end
124
+ end
125
+ no = (no || []).map { |val| (n = val.index('=')) ? val[0, n] : val }
126
+ bare.concat(no)
127
+ skip = false
128
+ opts.each do |opt|
129
+ next @extras << opt if skip
130
+
131
+ if single&.match?(opt)
132
+ target << "-#{opt}"
133
+ elsif bare.include?(opt)
134
+ target << (opt.size == 1 ? "-#{opt}" : "--#{opt}")
135
+ elsif opt.start_with?('no-') && no.include?(name = opt[3..-1])
136
+ target << "--no-#{name}"
137
+ else
138
+ if opt =~ /\A([^=]+)=(.+)\z/
139
+ key = $1
140
+ val = $2
141
+ match = ->(flag, pat) { flag.include?(key) && pat.match?(val) }
142
+ if e.include?(key)
143
+ target << shell_option(key, val)
144
+ elsif q.include?(key)
145
+ target << quote_option(key, val, double: qq.include?(key))
146
+ elsif p.include?(key) && path
147
+ target << quote_option(key, path.join(val))
148
+ elsif m.include?(key)
149
+ target << basic_option(key, val, merge: true)
150
+ elsif b.include?(key) || match.(i, /^\d+$/) || match.(f, /^\d*(?:\.\d+)?$/) || match.(si, /^-?\d+$/)
151
+ target << basic_option(key, val)
152
+ else
153
+ @extras << opt
154
+ end
155
+ opt = key
156
+ else
157
+ @extras << opt
158
+ skip = true if args
159
+ end
160
+ skip = true if first && pass.none? { |s| opt.include?(s) }
161
+ end
162
+ end
163
+ @values = @values.empty? ? /\A\s+\z/ : /\A(#{@values.join('|')})=(.+)\z/
164
+ @extras.each_with_index(&blk) if block_given?
165
+ self
166
+ end
167
+
168
+ def swap(opts = nil)
169
+ unless opts
170
+ opts = found
171
+ @found = []
172
+ end
173
+ @extras = opts
174
+ self
175
+ end
176
+
177
+ def append(*args, **kwargs)
178
+ OptionPartition.append(target, *(args.empty? ? extras : args), **kwargs)
179
+ self
180
+ end
181
+
182
+ def clear(opts = nil, **kwargs)
183
+ opts ||= (kwargs[:errors] ? errors : extras)
184
+ styles = project.theme[:inline] if project
185
+ OptionPartition.clear(target, opts.reject { |val| found.include?(val) }, styles: styles, **kwargs)
186
+ opts.clear
187
+ self
188
+ end
189
+
190
+ def arg?(*args, **kwargs)
191
+ OptionPartition.arg?(target, *args, **kwargs)
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'support/class'
@@ -22,5 +22,6 @@ module Squared
22
22
  end
23
23
  end
24
24
 
25
+ require_relative 'project/support'
25
26
  require_relative 'project/base'
26
27
  require_relative 'project/git'
@@ -135,7 +135,7 @@ module Squared
135
135
  task_desc(val, name: key)
136
136
  task key => items
137
137
  end
138
- @multiple += sync
138
+ @multiple.concat(sync)
139
139
  end
140
140
 
141
141
  def name_get(key)
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.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -97,6 +97,8 @@ files:
97
97
  - lib/squared/workspace/project/node.rb
98
98
  - lib/squared/workspace/project/python.rb
99
99
  - lib/squared/workspace/project/ruby.rb
100
+ - lib/squared/workspace/project/support.rb
101
+ - lib/squared/workspace/project/support/class.rb
100
102
  - lib/squared/workspace/repo.rb
101
103
  - lib/squared/workspace/series.rb
102
104
  - squared.gemspec
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  - !ruby/object:Gem::Version
122
124
  version: '0'
123
125
  requirements: []
124
- rubygems_version: 3.6.7
126
+ rubygems_version: 3.6.8
125
127
  specification_version: 4
126
128
  summary: Rake task generator for managing multi-language workspaces.
127
129
  test_files: []