shellopts 2.0.0 → 2.0.1

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: 6f6c85f64a45ee82fb4abdafd5d36358f8f7a202d9179a670cc86d307813b4a9
4
- data.tar.gz: 0a5e262777d044fe3afea501b3d94a8c44f89d4703924c619bfbbf2326e22a95
3
+ metadata.gz: 4f5448df8e0fdd882072ab927e185511b09ebd8b594a9556937fdfd20d41070d
4
+ data.tar.gz: 2743f77e88de6ff10562a2f7d3980b1bfc730d0e024e60e6472da48342a2f153
5
5
  SHA512:
6
- metadata.gz: 34d0eb7f8d15ba2726b062c9f16e36bf0b2649690e4b6487e8b68ce442436100a67928eb47d3896961281e78f77f9252f66f407ce2dafd652fae65d85c229c3d
7
- data.tar.gz: 9fc0e55ccde0175fea950a4cdd4f4dd385123e2e89c6ecfde8b4a1d0c6502054394322b2c673a96adfaabbbeaeee95d642034a8f545620286c8b795dc6da2436
6
+ metadata.gz: 9e08795c96b4f745a00cb6c38e5ea63beef08ceb640a0427d4bc46ee705189cab188a227a9d1775177d6530596155744d6e8624fa378c87c47f94c36e1adf98b
7
+ data.tar.gz: cb12f16c665fe6fc0e0751ad2328aa7d8e1e48baad9d9d27addb4d88f6a083d780c61ee0b8b57e8218ee829a6e107afa8c076067dfa5d24a973bf353489d7433
@@ -3,12 +3,8 @@ module ShellOpts
3
3
  # Specialization of Array for arguments lists. Args extends Array with a
4
4
  # #extract and an #expect method to extract elements from the array. The
5
5
  # methods raise a ShellOpts::UserError exception in case of errors
6
+ #
6
7
  class Args < Array
7
- def initialize(shellopts, *args)
8
- @shellopts = shellopts
9
- super(*args)
10
- end
11
-
12
8
  # Remove and return elements from beginning of the array
13
9
  #
14
10
  # If +count_or_range+ is a number, that number of elements will be
@@ -19,6 +15,7 @@ module ShellOpts
19
15
  #
20
16
  # #extract raise a ShellOpts::UserError exception if there's is not enough
21
17
  # elements in the array to satisfy the request
18
+ #
22
19
  def extract(count_or_range, message = nil)
23
20
  case count_or_range
24
21
  when Range
@@ -44,6 +41,7 @@ module ShellOpts
44
41
  #
45
42
  # #expect raise a ShellOpts::UserError exception if the array is not emptied
46
43
  # by the operation
44
+ #
47
45
  def expect(count_or_range, message = nil)
48
46
  case count_or_range
49
47
  when Range
@@ -57,7 +55,7 @@ module ShellOpts
57
55
 
58
56
  private
59
57
  def inoa(message = nil)
60
- raise Error.new(nil), message || "Illegal number of arguments"
58
+ raise ArgumentError, message || "Illegal number of arguments"
61
59
  end
62
60
  end
63
61
  end
@@ -32,7 +32,7 @@ module ShellOpts
32
32
  end
33
33
  end
34
34
  end
35
- [@expr, @args += @argv]
35
+ [@expr, Args.new(@args + @argv)]
36
36
  end
37
37
 
38
38
  def self.interpret(grammar, argv, **opts)
@@ -1,3 +1,3 @@
1
1
  module ShellOpts
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
data/lib/shellopts.rb CHANGED
@@ -21,6 +21,7 @@ require 'shellopts/stack.rb'
21
21
  require 'shellopts/token.rb'
22
22
  require 'shellopts/grammar.rb'
23
23
  require 'shellopts/program.rb'
24
+ require 'shellopts/args.rb'
24
25
  require 'shellopts/lexer.rb'
25
26
  require 'shellopts/argument_type.rb'
26
27
  require 'shellopts/parser.rb'
@@ -163,7 +164,7 @@ module ShellOpts
163
164
  def self.process(spec, argv, **opts)
164
165
  ::ShellOpts.instance = shellopts = ShellOpts.new(**opts)
165
166
  shellopts.process(spec, argv)
166
- [shellopts.program, shellopts.argv]
167
+ [shellopts.program, shellopts.args]
167
168
  end
168
169
 
169
170
  # Write short usage and error message to standard error and terminate
data/main CHANGED
@@ -19,13 +19,13 @@ SPEC = %(
19
19
  )
20
20
 
21
21
  opts, args = ShellOpts.process(SPEC, ARGV)
22
- puts "opts.alpha?: #{opts.alpha?.inspect}"
22
+ #puts "opts.alpha?: #{opts.alpha?.inspect}"
23
23
  #puts "opts.alpha: #{opts.alpha.inspect}"
24
- puts "opts.beta?: #{opts.beta?.inspect}"
25
- puts "opts.beta: #{opts.beta.inspect}"
26
- exit
27
- ShellOpts::ShellOpts.brief
28
- exit
24
+ #puts "opts.beta?: #{opts.beta?.inspect}"
25
+ #puts "opts.beta: #{opts.beta.inspect}"
26
+ #exit
27
+ #ShellOpts::ShellOpts.brief
28
+ #exit
29
29
 
30
30
 
31
31
 
@@ -277,11 +277,11 @@ shellopts.compile(SPEC)
277
277
  #shellopts.tokens.each(&:dump)
278
278
  #exit
279
279
 
280
- #shellopts.usage
280
+ shellopts.usage
281
281
  #shellopts.brief
282
282
  #shellopts.help
283
283
  #shellopts.help("cmd")
284
- shellopts.help(ARGV.first)
284
+ #shellopts.help(ARGV.first)
285
285
 
286
286
  #p shellopts.tokens
287
287
 
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.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen