shellopts 2.0.15 → 2.0.18
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.
- checksums.yaml +4 -4
- data/PROBLEMS +52 -0
- data/lib/ext/follow.rb +26 -0
- data/lib/shellopts/grammar.rb +2 -2
- data/lib/shellopts/program.rb +40 -35
- data/lib/shellopts/version.rb +1 -1
- data/lib/shellopts.rb +1 -0
- metadata +4 -2
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
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
# Subcommand options are not recognized unless there exists an option on the
|
3
|
+
# program level (try to remove -a below)
|
4
|
+
|
5
|
+
SPEC = %(
|
6
|
+
Foreign data wrapper maintenance tool
|
7
|
+
|
8
|
+
-a,an-option
|
9
|
+
Gryf
|
10
|
+
|
11
|
+
list.servers! -- DATABASE
|
12
|
+
List foreign servers
|
13
|
+
|
14
|
+
create.server! -- DATABASE FDW-SERVER MSSQL-DATABASE [MSSQL-HOST [MSSQL-PORT]]
|
15
|
+
Create a new FDW server
|
16
|
+
|
17
|
+
-c,credentials=EFILE
|
18
|
+
Credentials file. The credentials file is a YAML formatted file that can
|
19
|
+
define the fields 'user', 'password', 'host', and 'port'
|
20
|
+
|
21
|
+
drop.server! -- DATABASE FDW-SERVER
|
22
|
+
Drop a FDW server. This cascades to FDW users too
|
23
|
+
|
24
|
+
list.users! -- DATABASE
|
25
|
+
List FDW users. 'users' in this context is postgres users that have an
|
26
|
+
associated FDW user mapping
|
27
|
+
|
28
|
+
--servers @ Also list the user's FDW servers
|
29
|
+
|
30
|
+
create.user! -- DATABASE FDW-SERVER [FDW-USER [FDW-PASSWORD]]
|
31
|
+
Create a FDW user. The user has to exist beforehand, this command only adds
|
32
|
+
a user mapping to the user and grants the usage privilege
|
33
|
+
|
34
|
+
-c,credentials=EFILE
|
35
|
+
Credentials file
|
36
|
+
|
37
|
+
drop.user! -- DATABASE FDW-USER
|
38
|
+
Drops a FDW user. The postgres user is not dropped but the user's user
|
39
|
+
mapping and grants are
|
40
|
+
)
|
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/ext/follow.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
module Algorithm
|
3
|
+
class FollowEnumerator < Enumerator
|
4
|
+
def initialize(object, method = nil, &block)
|
5
|
+
closure = method ? lambda { |object| object.__send__(method) } : block
|
6
|
+
super() { |yielder|
|
7
|
+
while object
|
8
|
+
yielder << object
|
9
|
+
object = closure.call(object)
|
10
|
+
end
|
11
|
+
}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def follow(object, method = nil, &block)
|
16
|
+
!method.nil? || block_given? or raise ArgumentError, "Needs either a method or a block"
|
17
|
+
method.nil? == block_given? or raise ArgumentError, "Can't use both method and block"
|
18
|
+
FollowEnumerator.new(object, method, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
module_function :follow
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
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
@@ -52,7 +52,7 @@ module ShellOpts
|
|
52
52
|
# These methods can be overridden by an option or a command (this constant
|
53
53
|
# is not used - it is just for informational purposes)
|
54
54
|
OVERRIDEABLE_METHOD_NAMES = %w(
|
55
|
-
subcommand subcommand! supercommand!
|
55
|
+
subcommand subcommand! subcommands subcommands! supercommand!
|
56
56
|
)
|
57
57
|
|
58
58
|
# Redefine ::new to call #__initialize__
|
@@ -62,49 +62,37 @@ 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)
|
102
90
|
keys = ::Kernel::Array(keys).flatten
|
103
91
|
if keys.empty?
|
104
|
-
@
|
92
|
+
self.to_h(@__grammar__.options.map(&:ident))
|
105
93
|
else
|
106
94
|
keys.map { |key|
|
107
|
-
|
95
|
+
self.__send__("#{key}?".to_sym) ? [key, self.__send__(key)] : nil
|
108
96
|
}.compact.to_h
|
109
97
|
end
|
110
98
|
end
|
@@ -133,6 +121,13 @@ module ShellOpts
|
|
133
121
|
#
|
134
122
|
def subcommand!() __subcommand__! end
|
135
123
|
|
124
|
+
# Returns the concatenated identifier of subcommands (eg. :cmd.subcmd!)
|
125
|
+
def subcommands() __subcommands__ end
|
126
|
+
|
127
|
+
# Returns the subcommands in an array. This doesn't include the top-level
|
128
|
+
# program object
|
129
|
+
def subcommands!() __subcommands__! end
|
130
|
+
|
136
131
|
# The parent command or nil. Initialized by #add_command
|
137
132
|
#
|
138
133
|
# Note: Can be overridden by a subcommand declaration (but not an
|
@@ -141,7 +136,7 @@ module ShellOpts
|
|
141
136
|
#
|
142
137
|
def supercommand!() __supercommand__ end
|
143
138
|
|
144
|
-
# UID of command/program
|
139
|
+
# UID of command/program (String)
|
145
140
|
def __uid__() @__grammar__.uid end
|
146
141
|
|
147
142
|
# Identfier including the exclamation mark (Symbol)
|
@@ -155,8 +150,8 @@ module ShellOpts
|
|
155
150
|
|
156
151
|
# Hash from identifier to value. Can be Integer, Float, or String depending
|
157
152
|
# on the option's type. Repeated options options without arguments have the
|
158
|
-
# number of occurences as value
|
159
|
-
#
|
153
|
+
# number of occurences as value, repeated option with arguments have the
|
154
|
+
# array of values as value
|
160
155
|
attr_reader :__option_values__
|
161
156
|
|
162
157
|
# List of Option objects for the subcommand in the same order as
|
@@ -180,6 +175,16 @@ module ShellOpts
|
|
180
175
|
# The actual subcommand object or nil if not present
|
181
176
|
def __subcommand__!() @__subcommand__ end
|
182
177
|
|
178
|
+
# Implementation of the #subcommands method
|
179
|
+
def __subcommands__()
|
180
|
+
__subcommands__!.last&.__uid__&.to_sym
|
181
|
+
end
|
182
|
+
|
183
|
+
# Implementation of the #subcommands! method
|
184
|
+
def __subcommands__!()
|
185
|
+
::Algorithm.follow(self.__subcommand__!, :__subcommand__!).to_a
|
186
|
+
end
|
187
|
+
|
183
188
|
private
|
184
189
|
def __initialize__(grammar)
|
185
190
|
@__grammar__ = grammar
|
data/lib/shellopts/version.rb
CHANGED
data/lib/shellopts.rb
CHANGED
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.
|
4
|
+
version: 2.0.18
|
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-
|
11
|
+
date: 2022-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forward_to
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- ".rspec"
|
136
136
|
- ".ruby-version"
|
137
137
|
- Gemfile
|
138
|
+
- PROBLEMS
|
138
139
|
- README.md
|
139
140
|
- Rakefile
|
140
141
|
- TODO
|
@@ -147,6 +148,7 @@ files:
|
|
147
148
|
- doc/syntax.rb
|
148
149
|
- doc/syntax.txt
|
149
150
|
- lib/ext/array.rb
|
151
|
+
- lib/ext/follow.rb
|
150
152
|
- lib/ext/forward_to.rb
|
151
153
|
- lib/ext/lcs.rb
|
152
154
|
- lib/shellopts.rb
|