shellopts 2.9.4 → 2.9.6
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/lib/shellopts/analyzer.rb +8 -4
- data/lib/shellopts/formatter.rb +11 -2
- data/lib/shellopts/grammar.rb +2 -12
- data/lib/shellopts/lexer.rb +6 -2
- data/lib/shellopts/parser.rb +1 -1
- data/lib/shellopts/version.rb +1 -1
- data/lib/shellopts.rb +14 -5
- data/main +29 -15
- 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: 9b37c30aa585a54cf4683ef32bea5aa0ca0eabc7cdbb4d8e36ddc4d8a0f74747
|
|
4
|
+
data.tar.gz: 681b00e0bd4454b2b81dea46542c3c4579da6ba44d169bd4276b65d6c9c45168
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ddb846f437e6ceeb08f5c60a81408d1bbf17d2237bd9a01a2f41364833deac6e23c1f2478368a2c9fff2c50bd4679c1d389ae3ac29c3fa35140a0b34237d2bb4
|
|
7
|
+
data.tar.gz: f2cf6dae553ec03a33be9270925942f5f738cc4a768ee58325711f0971000607cffb9e940f82aef24a899cd5ec5c4536b3ef2ce684f42b2d52efb87419d5fe1c
|
data/lib/shellopts/analyzer.rb
CHANGED
|
@@ -27,12 +27,16 @@ module ShellOpts
|
|
|
27
27
|
# Move options before first command or before explicit COMMAND section
|
|
28
28
|
def reorder_options
|
|
29
29
|
if commands.any?
|
|
30
|
-
|
|
30
|
+
command_index = children.find_index { |child|
|
|
31
31
|
child.is_a?(Command) || child.is_a?(Section) && child.name == "COMMAND"
|
|
32
32
|
}
|
|
33
|
-
if
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if command_index
|
|
34
|
+
initial, rest = children[0...command_index], children[command_index..]
|
|
35
|
+
option_sections, rest = rest.partition { |child|
|
|
36
|
+
child.is_a?(Section) && child.name == "OPTION"
|
|
37
|
+
}
|
|
38
|
+
option_groups, rest = rest.partition { |child| child.is_a?(OptionGroup) }
|
|
39
|
+
@children = initial + option_sections + option_groups + rest
|
|
36
40
|
end
|
|
37
41
|
end
|
|
38
42
|
end
|
data/lib/shellopts/formatter.rb
CHANGED
|
@@ -26,6 +26,14 @@ module ShellOpts
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
class Section
|
|
30
|
+
# This is a hack since the section does not contain any elements - this
|
|
31
|
+
# is an error in the parser
|
|
32
|
+
def puts_descr
|
|
33
|
+
indent(-1) { print Ansi.bold(name) }
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
29
37
|
# brief one-line commands should optionally use compact options
|
|
30
38
|
class Command
|
|
31
39
|
using Ext::Array::Wrap
|
|
@@ -123,8 +131,8 @@ module ShellOpts
|
|
|
123
131
|
newline = false # True if a newline should be printed before child
|
|
124
132
|
indent {
|
|
125
133
|
children.each { |child|
|
|
126
|
-
klass = child.is_a?(Section) ?
|
|
127
|
-
if s = section[klass] #
|
|
134
|
+
klass = child.is_a?(Section) ? section.key(child.name) : child.class
|
|
135
|
+
if s = section[klass] # Built-in sections
|
|
128
136
|
section.delete(klass)
|
|
129
137
|
section.delete(Paragraph)
|
|
130
138
|
if klass <= OptionGroup
|
|
@@ -136,6 +144,7 @@ module ShellOpts
|
|
|
136
144
|
indent(-1) { puts Ansi.bold s }
|
|
137
145
|
newline = false
|
|
138
146
|
next if child.is_a?(Section)
|
|
147
|
+
|
|
139
148
|
else # Any other node adds a newline
|
|
140
149
|
puts if newline
|
|
141
150
|
newline = true
|
data/lib/shellopts/grammar.rb
CHANGED
|
@@ -22,12 +22,9 @@ module ShellOpts
|
|
|
22
22
|
@parent.send(:attach, self) if @parent
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def traverse(*klasses, &block)
|
|
26
|
-
do_traverse(Array(klasses).flatten, &block)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
25
|
def parents() parent ? [parent] + parent.parents : [] end
|
|
30
26
|
def ancestors() parents.reverse end
|
|
27
|
+
def traverse(*klasses, &block) = do_traverse(Array(klasses).flatten, &block)
|
|
31
28
|
|
|
32
29
|
def inspect
|
|
33
30
|
self.class.to_s
|
|
@@ -337,9 +334,6 @@ module ShellOpts
|
|
|
337
334
|
alias_method :command, :parent
|
|
338
335
|
end
|
|
339
336
|
|
|
340
|
-
class Usage < ArgDescr
|
|
341
|
-
end
|
|
342
|
-
|
|
343
337
|
module WrappedNode
|
|
344
338
|
using Ext::Array::Wrap
|
|
345
339
|
def words() @words ||= text.split(" ") end
|
|
@@ -362,10 +356,6 @@ module ShellOpts
|
|
|
362
356
|
end
|
|
363
357
|
|
|
364
358
|
class Section < Node
|
|
365
|
-
def initialize(parent, token)
|
|
366
|
-
constrain token.source, *%w(DESCRIPTION OPTION COMMAND)
|
|
367
|
-
super
|
|
368
|
-
end
|
|
369
359
|
def name() token.source end
|
|
370
360
|
end
|
|
371
361
|
|
|
@@ -379,7 +369,7 @@ module ShellOpts
|
|
|
379
369
|
Arg => [ArgSpec],
|
|
380
370
|
ArgDescr => [Command],
|
|
381
371
|
Brief => [Command, OptionGroup, ArgSpec, ArgDescr],
|
|
382
|
-
Paragraph => [Command, OptionGroup],
|
|
372
|
+
Paragraph => [Command, OptionGroup, Section],
|
|
383
373
|
Code => [Command, OptionGroup],
|
|
384
374
|
Section => [Program]
|
|
385
375
|
}
|
data/lib/shellopts/lexer.rb
CHANGED
|
@@ -3,7 +3,7 @@ module ShellOpts
|
|
|
3
3
|
class Line
|
|
4
4
|
attr_reader :source
|
|
5
5
|
attr_reader :lineno
|
|
6
|
-
attr_reader :charno
|
|
6
|
+
attr_reader :charno # aka "indent + 1"
|
|
7
7
|
attr_reader :text
|
|
8
8
|
|
|
9
9
|
def initialize(lineno, charno, source)
|
|
@@ -107,10 +107,14 @@ module ShellOpts
|
|
|
107
107
|
@tokens << Token.new(kind, line.lineno, line.charno, line.text)
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
#
|
|
110
|
+
# Built-in sections
|
|
111
111
|
elsif SECTIONS.include?(line.text)
|
|
112
112
|
@tokens << Token.new(:section, line.lineno, line.charno, line.text.sub(/S$/, ""))
|
|
113
113
|
|
|
114
|
+
# User-defined sections
|
|
115
|
+
elsif line.text =~ /^[^a-z]*$/ && lines.first && lines.first.charno > line.charno
|
|
116
|
+
@tokens << Token.new(:section, line.lineno, line.charno, line)
|
|
117
|
+
|
|
114
118
|
# Options, commands, usage, arguments, and briefs
|
|
115
119
|
elsif line =~ DECL_RE
|
|
116
120
|
words = line.words
|
data/lib/shellopts/parser.rb
CHANGED
|
@@ -244,7 +244,7 @@ module ShellOpts
|
|
|
244
244
|
Grammar::ArgDescr.parse(cmds.top, token)
|
|
245
245
|
|
|
246
246
|
when :text
|
|
247
|
-
# Text is only allowed on new lines
|
|
247
|
+
# Text is only allowed on new lines. FIXME Does nothing
|
|
248
248
|
token.lineno > nodes.top.token.lineno
|
|
249
249
|
|
|
250
250
|
# Detect indented comment groups (code)
|
data/lib/shellopts/version.rb
CHANGED
data/lib/shellopts.rb
CHANGED
|
@@ -40,6 +40,7 @@ require_relative 'shellopts/dump.rb'
|
|
|
40
40
|
# prints an intelligble error message and prettyfies stack dump. This
|
|
41
41
|
# should catch non-RuntimeError/IOError exceptions
|
|
42
42
|
# * Find a reliable way of testing environment
|
|
43
|
+
#
|
|
43
44
|
|
|
44
45
|
module ShellOpts
|
|
45
46
|
# Base error class
|
|
@@ -171,6 +172,7 @@ module ShellOpts
|
|
|
171
172
|
@debug = debug
|
|
172
173
|
@float = float
|
|
173
174
|
@exception = exception
|
|
175
|
+
@clear_screen = true
|
|
174
176
|
end
|
|
175
177
|
|
|
176
178
|
# Compile source and return grammar object. Also sets #spec and #grammar.
|
|
@@ -299,11 +301,11 @@ module ShellOpts
|
|
|
299
301
|
def brief() Formatter.brief(@grammar) end
|
|
300
302
|
|
|
301
303
|
# Print help for the given subject or the full documentation if +subject+
|
|
302
|
-
# is nil. Clears the screen beforehand if
|
|
303
|
-
def help(subject = nil
|
|
304
|
+
# is nil. Clears the screen beforehand if #clear_screen is true
|
|
305
|
+
def help(subject = nil)
|
|
304
306
|
node = (subject ? @grammar[subject] : @grammar) or
|
|
305
307
|
raise ArgumentError, "No such command: '#{subject&.sub(".", " ")}'"
|
|
306
|
-
print '[H[2J' if
|
|
308
|
+
print '[H[2J' if ::ShellOpts.clear_screen
|
|
307
309
|
Formatter.help(node)
|
|
308
310
|
end
|
|
309
311
|
|
|
@@ -445,8 +447,15 @@ module ShellOpts
|
|
|
445
447
|
def self.exception = @exception
|
|
446
448
|
def self.exception=(value) @exception = value end
|
|
447
449
|
|
|
448
|
-
#
|
|
449
|
-
#
|
|
450
|
+
# Controls whether the --help option clears the screen before printing. This
|
|
451
|
+
# can be set to false in development to prevent debug output from being
|
|
452
|
+
# cleared
|
|
453
|
+
@clear_screen = true
|
|
454
|
+
def self.clear_screen = @clear_screen
|
|
455
|
+
def self.clear_screen=(clear) @clear_screen = clear end
|
|
456
|
+
|
|
457
|
+
# The instance is a ShellOpts object. 'instance.program' and 'instance.args'
|
|
458
|
+
# are the same as the values returned from ShellOpts.process
|
|
450
459
|
@instance = nil
|
|
451
460
|
def self.instance?() !@instance.nil? end
|
|
452
461
|
def self.instance() @instance or raise Error, "ShellOpts is not initialized" end
|
data/main
CHANGED
|
@@ -4,25 +4,39 @@
|
|
|
4
4
|
|
|
5
5
|
require_relative 'lib/shellopts.rb'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
#include ShellOpts::Debug
|
|
7
|
+
include ShellOpts
|
|
8
|
+
ShellOpts.clear_screen = false
|
|
10
9
|
|
|
11
|
-
#include ShellOpts::Messages
|
|
12
|
-
#p ShellOpts::Messages.is_included?
|
|
13
10
|
SPEC = %(
|
|
14
|
-
|
|
11
|
+
@ Make RLS functions and policies
|
|
12
|
+
|
|
13
|
+
-- [DATABASE] SPEC-FILE
|
|
14
|
+
|
|
15
|
+
Read SPEC-FILE and generate acl_portal.acl_* data. DATABASE and USERNAME
|
|
16
|
+
variables are read from the environment and then .prick.state.yml if present;
|
|
17
|
+
otherwise the current user's database is used
|
|
18
|
+
|
|
19
|
+
OPTIONS
|
|
20
|
+
--dump
|
|
21
|
+
Dump internal format. Used for debugging
|
|
22
|
+
|
|
23
|
+
COMMANDS
|
|
24
|
+
update!
|
|
25
|
+
Update the current database. This just keeps the IDs in acl_tables
|
|
26
|
+
stable, all other involved tables are cleared before loading
|
|
27
|
+
|
|
28
|
+
SPEC FILE
|
|
29
|
+
The format is a YAML file where each root key represents a table. A table
|
|
30
|
+
consists of select, insert, update, delete, and attach/detach actions that
|
|
31
|
+
are arrays of ACL entries
|
|
32
|
+
|
|
33
|
+
ANOTHER SUBJECT
|
|
34
|
+
Bla bla bla
|
|
15
35
|
|
|
16
|
-
-a
|
|
17
|
-
An option
|
|
18
36
|
)
|
|
19
37
|
|
|
20
|
-
opts, args = ShellOpts.process(SPEC, ARGV
|
|
38
|
+
opts, args = ShellOpts.process(SPEC, ARGV)
|
|
21
39
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
mesg "Message"
|
|
25
|
-
notice "Notice"
|
|
26
|
-
#debug "Debug"
|
|
27
|
-
puts ShellOpts.instance.version_number
|
|
40
|
+
pp opts.to_h
|
|
41
|
+
pp args
|
|
28
42
|
|