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 +4 -4
- data/PROBLEMS +11 -0
- data/lib/shellopts/grammar.rb +2 -2
- data/lib/shellopts/program.rb +18 -30
- data/lib/shellopts/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43a4d96ef2927b72add380e17e0dad25b2004659491a5dc4adb36f3c9965c8c9
|
4
|
+
data.tar.gz: 507780f5ea40771db0ffbc4d0247b9f8f5d08044953dc0c387e92432c42879df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
|
data/lib/shellopts/grammar.rb
CHANGED
@@ -30,7 +30,7 @@ module ShellOpts
|
|
30
30
|
def ancestors() parents.reverse end
|
31
31
|
|
32
32
|
def inspect
|
33
|
-
|
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.
|
244
|
+
when Symbol; lookup(key.to_s.gsub(".", "!.").split(".").map(&:to_sym))
|
245
245
|
when Array; lookup(key)
|
246
246
|
else
|
247
247
|
nil
|
data/lib/shellopts/program.rb
CHANGED
@@ -62,40 +62,28 @@ module ShellOpts
|
|
62
62
|
object
|
63
63
|
end
|
64
64
|
|
65
|
-
#
|
66
|
-
# possibly empty array of option objects if the
|
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
|
69
|
-
#
|
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 [](
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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__[
|
81
|
-
|
82
|
-
|
83
|
-
|
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)
|
data/lib/shellopts/version.rb
CHANGED