squared 0.9.0.pre1 → 0.9.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.
@@ -37,12 +37,12 @@ module Squared
37
37
  end
38
38
  end
39
39
 
40
- def insert(*args)
41
- replace Set.new(compact.insert(*args))
40
+ def insert(...)
41
+ replace Set.new(compact.insert(...))
42
42
  end
43
43
 
44
- def slice(*args)
45
- compact.slice(*args)
44
+ def slice(...)
45
+ compact.slice(...)
46
46
  end
47
47
 
48
48
  def slice!(*args)
@@ -168,16 +168,16 @@ module Squared
168
168
  to_a.join(@delim)
169
169
  end
170
170
 
171
- def to_enum(*args)
172
- to_a.to_enum(*args)
171
+ def to_enum(...)
172
+ to_a.to_enum(...)
173
173
  end
174
174
 
175
- def to_json(*args)
176
- to_a.to_json(*args)
175
+ def to_json(...)
176
+ to_a.to_json(...)
177
177
  end
178
178
 
179
- def to_yaml(*args)
180
- to_a.to_yaml(*args)
179
+ def to_yaml(...)
180
+ to_a.to_yaml(...)
181
181
  end
182
182
 
183
183
  alias add :<<
@@ -220,6 +220,7 @@ module Squared
220
220
  end
221
221
 
222
222
  attr_reader :target, :extras, :found, :errors, :values, :project, :path, :sep
223
+ attr_accessor :stdout
223
224
 
224
225
  def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
225
226
  :merge, :compact, :delete, :delete?, :delete_if, :grep, :grep_v, :inspect, :to_a, :to_s
@@ -242,14 +243,16 @@ module Squared
242
243
  @sep = sep
243
244
  @errors = []
244
245
  @found = []
246
+ @stdout = false
245
247
  parse(list, opts, **kwargs, &blk)
246
248
  end
247
249
 
248
250
  def parse(list, opts = extras, no: nil, single: nil, args: false, multiple: nil, first: nil, underscore: nil,
249
- explicit: false, bool: %w[true false], stdin: false, &blk)
251
+ explicit: false, bool: %w[true false], auto: [], stdin: false, &blk)
250
252
  @extras = []
251
253
  @values = []
252
254
  bare = []
255
+ auto = auto.flat_map { |val| val.split('|', 2) }
253
256
  e = []
254
257
  b = []
255
258
  m = []
@@ -351,6 +354,7 @@ module Squared
351
354
  tr = ->(a) { a.map { |val| val.tr('-', '_') } }
352
355
  @values.concat(tr.call(@values))
353
356
  bare.concat(tr.call(bare))
357
+ auto.concat(tr.call(auto))
354
358
  e.concat(tr.call(e))
355
359
  b.concat(tr.call(b))
356
360
  m.concat(tr.call(m))
@@ -364,6 +368,7 @@ module Squared
364
368
  ml.concat(tr.call(ml))
365
369
  no.concat(tr.call(no))
366
370
  end
371
+ bare.concat(auto)
367
372
  if target.is_a?(JoinSet)
368
373
  target.multiple = multiple if multiple
369
374
  target.multiple = ml.map { |val| val.size == 1 ? "-#{val}" : "--#{val}" }
@@ -396,6 +401,10 @@ module Squared
396
401
  add "#{sw[opt]}#{opt}"
397
402
  else
398
403
  add(opt.size == 1 ? "-#{opt}" : "--#{opt}")
404
+ if auto.include?(opt)
405
+ @stdout = true
406
+ break
407
+ end
399
408
  end
400
409
  elsif opt.start_with?(/no[-_]/) && no.include?(s = opt[3..])
401
410
  add "--no-#{s}"
@@ -822,6 +831,10 @@ module Squared
822
831
  end
823
832
  end
824
833
 
834
+ def style?(*args)
835
+ !stdout && args.none?(&:!)
836
+ end
837
+
825
838
  def uniq!(list)
826
839
  list = uniq list
827
840
  return if list.empty?
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.9.0.pre1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham