shellopts 2.0.17 → 2.0.18

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: ebd7911e579af4ddddd064399e7b456b45cef80dc3c6589e404ba5e32811bd6c
4
- data.tar.gz: ea555ad68d0d6c43bad39a4e195e6661f72e1e43b6d3dbe647f4c8ff13d7eea3
3
+ metadata.gz: 43a4d96ef2927b72add380e17e0dad25b2004659491a5dc4adb36f3c9965c8c9
4
+ data.tar.gz: 507780f5ea40771db0ffbc4d0247b9f8f5d08044953dc0c387e92432c42879df
5
5
  SHA512:
6
- metadata.gz: 453d3bd1e4354a56947623232f1fabcdc8d212a91d317ce16026c356c71c77ab53031e4e42d05242d0c04ce309ccd69fd75386d3d40705feac461f58d6a2c86b
7
- data.tar.gz: 282655ab16154e1b50c25b6ddf8a07196a296f8a2bad4086cd78b8962a9003c22e1fb8dfbe2e339fc97973fef95b1cf9965a829bab23b2ad98f63df1aef8c009
6
+ metadata.gz: d57c4a7245f5c22b74c762d986b8a80ca331643a3f32f63421f08f412da01e3f6e21c76e0fe1921fa8337ad2cbc168e00bb9f722f3ebfc1fdb7468619169658d
7
+ data.tar.gz: 4ab7b06dd787db06af9ca0d70f6d44a26e251707badef5beecdb3bb719a3fc1bebf5357f00df2702589f4ea6960ebc6af83329adadc3e65bd2746e3dbb536fca
data/PROBLEMS CHANGED
@@ -39,3 +39,14 @@ SPEC = %(
39
39
  mapping and grants are
40
40
  )
41
41
 
42
+ ###########################
43
+
44
+ # If option is only defined on a subcommand, it doesn't flow before the subcommand. This should be legal:
45
+
46
+ cmd -c sub
47
+
48
+ # Only this is legal today
49
+
50
+ cmd sub -c
51
+
52
+
@@ -30,7 +30,7 @@ module ShellOpts
30
30
  def ancestors() parents.reverse end
31
31
 
32
32
  def inspect
33
- "#{self.class}"
33
+ self.class.to_s
34
34
  end
35
35
 
36
36
  protected
@@ -241,7 +241,7 @@ module ShellOpts
241
241
  def [](key)
242
242
  case key
243
243
  when String; lookup(key.split("."))
244
- when Symbol; lookup(key.to_s.sub(".", "!.").split(".").map(&:to_sym))
244
+ when Symbol; lookup(key.to_s.gsub(".", "!.").split(".").map(&:to_sym))
245
245
  when Array; lookup(key)
246
246
  else
247
247
  nil
@@ -62,40 +62,28 @@ module ShellOpts
62
62
  object
63
63
  end
64
64
 
65
- # Return command or option object if present, otherwise nil. Returns a
66
- # possibly empty array of option objects if the option is repeatable
65
+ # Returns the command or option object identified by the UID if present and
66
+ # otherwise nil. Returns a possibly empty array of option objects if the
67
+ # option is repeatable. Raise an ArgumentError if the key doesn't exists
67
68
  #
68
- # The key is the name or identifier of the object or any any option
69
- # alias. Eg. :f, '-f', :file, or '--file' are all usable as option keys
70
- # and :cmd! or 'cmd' as command keys
69
+ # The +key+ is the symbolic UID of the object. Eg. :command.option or
70
+ # :command.subcommand!
71
71
  #
72
- def [](key)
73
- case object = __grammar__[key]
74
- when ::ShellOpts::Grammar::Command
75
- object.ident == __subcommand__!.__ident__ ? __subcommand__! : nil
76
- when ::ShellOpts::Grammar::Option
77
- if object.repeatable?
78
- __option_hash__[object.ident] || []
72
+ def [](uid)
73
+ __grammar__.key?(uid) or ::Kernel.raise ::ArgumentError, "'#{uid}' is not a valid UID"
74
+ idents = uid.to_s.gsub(/\./, "!.").split(/\./).map(&:to_sym)
75
+ idents.inject(self) { |cmd, ident|
76
+ case ident.to_s
77
+ when /!$/
78
+ return nil if cmd.__subcommand__ != ident
79
+ cmd = cmd.__subcommand__!
79
80
  else
80
- __option_hash__[object.ident]
81
- end
82
- else
83
- ::Kernel.raise ::ArgumentError, "Unknown command or option: '#{key}'"
84
- end
81
+ opt = cmd.__option_hash__[ident]
82
+ opt.nil? && cmd.__grammar__[ident].repeatable? ? [] : opt
83
+ end
84
+ }
85
85
  end
86
86
 
87
- # Return true if the given command or option is present
88
- def key?(key)
89
- case object = __grammar__[key]
90
- when ::ShellOpts::Grammar::Command
91
- object.ident == __subcommand__
92
- when ::ShellOpts::Grammar::Option
93
- __option_hash__.key?(object.ident)
94
- else
95
- ::Kernel.raise ::ArgumentError, "Unknown command or option: '#{key}'"
96
- end
97
- end
98
-
99
87
  # Returns a hash of the given options if defined. Returns all options if no
100
88
  # options are given
101
89
  def to_h(*keys)
@@ -148,7 +136,7 @@ module ShellOpts
148
136
  #
149
137
  def supercommand!() __supercommand__ end
150
138
 
151
- # UID of command/program
139
+ # UID of command/program (String)
152
140
  def __uid__() @__grammar__.uid end
153
141
 
154
142
  # Identfier including the exclamation mark (Symbol)
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.0.17"
2
+ VERSION = "2.0.18"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellopts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.17
4
+ version: 2.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen