shellopts 2.0.19 → 2.0.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35b9e7b5699cc1a5637d4c00dd95c74047074f1227b0d05f9a9c8b04e1e2cc8b
4
- data.tar.gz: c8deed23c8e6f0b26d080e15d2830edb5e65d1b5f2f821ccd83db7db27d7aefd
3
+ metadata.gz: 83e0ce72f27c72eec2087bee9296378fc0d84fc1124f830af27f21340cefffcc
4
+ data.tar.gz: 6c3b2363c1ca392b0950c792c48e353181f352ca22bfe16e7c42490248511b29
5
5
  SHA512:
6
- metadata.gz: 5d3e96ec825ca58c0e653613ab84e2ede3e661737f5699571c81aaf9b2cb1252ea802581e5b981a1757d8a5a750ba998c43730c6d2da7d8228b721b06a45640e
7
- data.tar.gz: e64eeac4c3bf784f8ef3a5e3a61c596e262bd23c4ee05857f76138f82ff2180afb72ccd5c2b7ffedc4e6aa2887b10c76e3a80c33e24ceadd20e71513549b5bf0
6
+ metadata.gz: dcc6e2271a451f494e007c78e9054c49bbb6f65f0f0fcf5be07158488157782c8216fc0f6fce7e4c25dda6bf0e39ac8ae2096f733cb4af7c4b1360b28a978129
7
+ data.tar.gz: e1d60f792447e5884f2ad939fbf408d5c053ef413328e2e2a42a082e34e9672537d8d64916fbc136f11797ac2c87894c148939d4feac9cc43489d3c66faa538d
data/TODO CHANGED
@@ -1,3 +1,19 @@
1
+
2
+ o Make opts[] point at the main object
3
+ opts[].subcommand is the direct subcommand of main
4
+ o Make opts be the aggrated set of options in a subcommand
5
+ opts.subcommand is the concatenated path of subcommands
6
+ o Make opts[:some_command] be the set of options for that subcommand (already done)
7
+ o Sub-command options can overshadow options of outer commands but it is an
8
+ error to access them using opts. Use opts[] or opts[:some_command] instead
9
+
10
+ o Add a default argument to extract:
11
+ def extract(range, *defaults)
12
+ end
13
+
14
+ extract(3..4, 'dbo')
15
+
16
+ o More strict parsing of option and command lines
1
17
  o --option can't be escaped if on the start of a block line?
2
18
  o Use require_relative
3
19
  o In the following list is a command with a mandatory sub-command
@@ -84,19 +84,27 @@ module ShellOpts
84
84
  }
85
85
  end
86
86
 
87
- # Returns a hash of the given options if defined. Returns all options if no
88
- # options are given
87
+ # Returns a hash from option ident to value
88
+ #
89
+ # The value depends on the option type: If it is not repeatable, the value
90
+ # is the argument or nil if not present (or allowed). If the option is
91
+ # repeatable and has an argument, the value is an array of the arguments,
92
+ # if it doesn't have an argument, the value is the number of occurrences
93
+ #
89
94
  def to_h(*keys)
90
95
  keys = ::Kernel::Array(keys).flatten
91
- if keys.empty?
92
- self.to_h(@__grammar__.options.map(&:ident))
93
- else
94
- keys.map { |key|
95
- self.__send__("#{key}?".to_sym) ? [key, self.__send__(key)] : nil
96
- }.compact.to_h
97
- end
96
+ __option_values__.select { |key,_| keys.empty? || keys.include?(key) }
98
97
  end
99
98
 
99
+ # Like #to_h but present options without arguments have a true value
100
+ #
101
+ def to_h?(*keys)
102
+ keys = ::Kernel::Array(keys).flatten
103
+ keys = keys.empty? ? __option_values__.keys : keys
104
+ keys.filter_map { |key| __option_values__.key?(key) && [key, self.__send__(key)] }.to_h
105
+ end
106
+
107
+
100
108
  # Subcommand identifier or nil if not present. #subcommand is often used in
101
109
  # case statement to branch out to code that handles the given subcommand:
102
110
  #
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.0.19"
2
+ VERSION = "2.0.20"
3
3
  end
data/lib/shellopts.rb CHANGED
@@ -382,7 +382,6 @@ module ShellOpts
382
382
  end
383
383
  end
384
384
 
385
-
386
385
  def self.process(spec, argv, quiet: nil, verbose: nil, debug: nil, **opts)
387
386
  constrain quiet, String, true, false, nil
388
387
  quiet = quiet.nil? ? Message.is_included? || Verbose.is_included? : quiet
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellopts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.19
4
+ version: 2.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-16 00:00:00.000000000 Z
11
+ date: 2022-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forward_to