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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7defb9acfdec63e96a3ecb7d75c507d3bde7df529e5184d64721da771b8153f8
4
- data.tar.gz: 4597ce11597a9e1f3a332b92a5ffc68a1460a59afbb18bf545bc31bd49056906
3
+ metadata.gz: 9b37c30aa585a54cf4683ef32bea5aa0ca0eabc7cdbb4d8e36ddc4d8a0f74747
4
+ data.tar.gz: 681b00e0bd4454b2b81dea46542c3c4579da6ba44d169bd4276b65d6c9c45168
5
5
  SHA512:
6
- metadata.gz: 7d295bf5a9c353192cd2a7332003d0947ecf45c9fee698a97949389b57ad04155f102625a69749380eee372cad81451fe9d2eb9f6c477e67948f83c4140b51f8
7
- data.tar.gz: b18c805a3b6212ad52f59bcbbcd3ab845fae9335ec02237a454070081e8e31580ac256a83c9a2fc8da5c4f6411800ce8ed14de306e08339f8a46d2a23b7358ae
6
+ metadata.gz: ddb846f437e6ceeb08f5c60a81408d1bbf17d2237bd9a01a2f41364833deac6e23c1f2478368a2c9fff2c50bd4679c1d389ae3ac29c3fa35140a0b34237d2bb4
7
+ data.tar.gz: f2cf6dae553ec03a33be9270925942f5f738cc4a768ee58325711f0971000607cffb9e940f82aef24a899cd5ec5c4536b3ef2ce684f42b2d52efb87419d5fe1c
@@ -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
- i = children.find_index { |child|
30
+ command_index = children.find_index { |child|
31
31
  child.is_a?(Command) || child.is_a?(Section) && child.name == "COMMAND"
32
32
  }
33
- if i
34
- options, rest = children[i+1..-1].partition { |child| child.is_a?(OptionGroup) }
35
- @children = children[0, i] + options + children[i..i] + rest
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
@@ -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) ? section.key(child.name) : child.class
127
- if s = section[klass] # Implicit section
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
@@ -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
  }
@@ -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
- # Sections
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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.9.4"
2
+ VERSION = "2.9.6"
3
3
  end
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 :clear is true
303
- def help(subject = nil, clear: true)
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 '' if clear
308
+ print '' 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
- # The instance is a ShellOpts object. 'instance.program' and 'instance.argv'
449
- # is the same as the values returned from ShellOpts.process
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
- #include ShellOpts::Message
8
- include ShellOpts::Verbose
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
- Test
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, version: "--ver", version_number: "1.2.3")
38
+ opts, args = ShellOpts.process(SPEC, ARGV)
21
39
 
22
- verb "Verbose default"
23
- (0..3).each { |i| verb i, "Verbose #{i}" }
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
 
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.9.4
4
+ version: 2.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen