shellopts 2.0.0 → 2.0.3

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: c3b7401560ce40fd21fcbc1e1c666464f2b01a4da8a93a4ec32010aa480bb8aa
4
+ data.tar.gz: f998e1ab794ab4e1b711d72e7d4e6820304ab6733bc9ae9d1fa137ab4323c633
5
5
  SHA512:
6
- metadata.gz: 34d0eb7f8d15ba2726b062c9f16e36bf0b2649690e4b6487e8b68ce442436100a67928eb47d3896961281e78f77f9252f66f407ce2dafd652fae65d85c229c3d
7
- data.tar.gz: 9fc0e55ccde0175fea950a4cdd4f4dd385123e2e89c6ecfde8b4a1d0c6502054394322b2c673a96adfaabbbeaeee95d642034a8f545620286c8b795dc6da2436
6
+ metadata.gz: a9b7856eb14fa2166bbc80dcace1724ee1a6499e93ce63f4971bdc9c4b27df4e5b26bc9d147a728de059d6e25d4e561a24aff39e2add47ca9a29aa5ad186b88f
7
+ data.tar.gz: 2cf14edab9a3cbb43ed3991596574e372af6527736031bd04626fb202cdf739b46565cee5c19cc67e46573c570651b7290852728958b075eeabe0df4f5197b0b
@@ -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
@@ -14,8 +14,8 @@ module ShellOpts
14
14
  # safe for concurrent processing
15
15
  attr_reader :message
16
16
 
17
- # Return true if .value is an "instance" of self (not used atm. See
18
- # Command#[] and Grammar::Option#value?)
17
+ # Return true if .value is an "instance" of self. Ie. an Integer object
18
+ # if type is an IntegerArgument
19
19
  def value?(value) true end
20
20
 
21
21
  # Convert value to Ruby type
@@ -131,7 +131,7 @@ module ShellOpts
131
131
  class EnumArgument < ArgumentType
132
132
  attr_reader :values
133
133
  def initialize(values) @values = values.dup end
134
- def match?(name, literal) literal?(literal) or set_message "Illegal value in #{name}: '#{literal}'" end
134
+ def match?(name, literal) value?(literal) or set_message "Illegal value in #{name}: '#{literal}'" end
135
135
  def value?(value) @values.include?(value) end
136
136
  end
137
137
  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.3"
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen