shellopts 2.0.0.pre.8 → 2.0.0.pre.9

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: b967bc79076cae64e2c68c3ef559568a4324d94f7d87800937b746e09755fcfe
4
- data.tar.gz: 14c6a5866c6b33da7f7a27f050de46d03b7936842c366fb7b32121324f17d7b0
3
+ metadata.gz: abf197d1a00cb875a6ac80ba5dd672bfdf035778f2e281baa151b61b4ffb4644
4
+ data.tar.gz: 2e4f6a91002acbdd0ad2f528305e559606accb5f9b6f2b6610f88851a0cbd981
5
5
  SHA512:
6
- metadata.gz: de339ab12a1ef41f75cbb386a6778adc0dca989f64e9180780c1e00276303824dacca681ccba287f746e0bf7b436b717384be48feb02b4b9faf4be3852c533a5
7
- data.tar.gz: a4b286f8297d56afc672a8e9f21119580496c820a8377a419a1aca1905a08e67a5763ed1aa14678137a9c739f120d673a1227d7a18233b43a482e8c43c603d92
6
+ metadata.gz: 6297e1adbf0a1a6f9a6c3b1057ae2a9c904cc34f4dfad26ee9ae25f48400476ea128b3c834e23cbe0ed746a1c11a69001c74dcd422ec06eec04b3138b855cbf3
7
+ data.tar.gz: bc9b0549d18774cdfac16150693e30b707bae6eb718ee36f8964405a78794335aea39386cb67e5457b7652e276fd244e9f6ec88d73577756e87d7f9490fd80b4
@@ -135,6 +135,7 @@ module ShellOpts
135
135
  def self.process(spec, argv, name: ::ShellOpts.default_name, usage: ::ShellOpts.default_usage)
136
136
  @shellopts.nil? or reset
137
137
  @shellopts = ShellOpts.new(spec, argv, name: name, usage: usage)
138
+ @shellopts.process
138
139
  end
139
140
 
140
141
  # Process command line, set current shellopts object, and return a
@@ -2,21 +2,23 @@
2
2
  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
- # methods call #error() in response to errors
5
+ # methods raise a ShellOpts::UserError exception in case of errors
6
6
  class Args < Array
7
7
  def initialize(shellopts, *args)
8
8
  @shellopts = shellopts
9
9
  super(*args)
10
10
  end
11
11
 
12
- # Remove and return elements from beginning of the array. If
13
- # +count_or_range+ is a number, that number of elements will be returned.
14
- # If the count is one, a simple value is returned instead of an array. If
15
- # the count is negative, the elements will be removed from the end of the
16
- # array. If +count_or_range+ is a range, the number of elements returned
17
- # will be in that range. The range can't contain negative numbers #expect
18
- # calls #error() if there's is not enough elements in the array to satisfy
19
- # the request
12
+ # Remove and return elements from beginning of the array
13
+ #
14
+ # If +count_or_range+ is a number, that number of elements will be
15
+ # returned. If the count is one, a simple value is returned instead of an
16
+ # array. If the count is negative, the elements will be removed from the
17
+ # end of the array. If +count_or_range+ is a range, the number of elements
18
+ # returned will be in that range. The range can't contain negative numbers
19
+ #
20
+ # #extract raise a ShellOpts::UserError exception if there's is not enough
21
+ # elements in the array to satisfy the request
20
22
  def extract(count_or_range, message = nil)
21
23
  if count_or_range.is_a?(Range)
22
24
  range = count_or_range
@@ -33,8 +35,11 @@ module ShellOpts
33
35
  end
34
36
  end
35
37
 
36
- # As extract except it doesn't allow negative counts and that the array is
38
+ # As #extract except it doesn't allow negative counts and that the array is
37
39
  # expect to be emptied by the operation
40
+ #
41
+ # #expect raise a ShellOpts::UserError exception if the array is not emptied
42
+ # by the operation
38
43
  def expect(count_or_range, message = nil)
39
44
  count_or_range === self.size or inoa(message)
40
45
  extract(count_or_range) # Can't fail
@@ -39,17 +39,16 @@ module ShellOpts
39
39
  # The IDR generated from the Ast
40
40
  attr_reader :idr
41
41
 
42
- # Compile a spec string into a grammar and use that to parse command line
43
- # arguments
42
+ # Compile a spec string into a grammar
44
43
  #
45
44
  # +spec+ is the spec string, and +argv+ the command line (typically the
46
45
  # global ARGV array). +name+ is the name of the program and defaults to the
47
46
  # basename of the program
48
47
  #
49
- # Syntax errors in the spec string are caused by the developer and raise a
50
- # +ShellOpts::CompilerError+ exception. Errors in the +argv+ arguments are
51
- # caused by the user and terminates the program with an error message and a
52
- # short description of its spec
48
+ # Syntax errors in the spec string are caused by the developer and cause
49
+ # #initialize to raise a +ShellOpts::CompilerError+ exception. Errors in
50
+ # the +argv+ arguments are caused by the user and cause #process to raise
51
+ # ShellOpts::UserError exception
53
52
  #
54
53
  # TODO: Change to (name, spec, argv, usage: nil) because
55
54
  # ShellOpts::ShellOpts isn't a magician like the ShellOpts module
@@ -60,13 +59,21 @@ module ShellOpts
60
59
  @argv = argv
61
60
  begin
62
61
  @grammar = Grammar.compile(@name, @spec)
63
- @ast = Ast.parse(@grammar, @argv)
64
- @idr = Idr.generate(self)
65
62
  rescue Grammar::Compiler::Error => ex
66
63
  raise CompilerError.new(5, ex.message)
64
+ end
65
+ end
66
+
67
+ # Process command line arguments and return self. Raises a
68
+ # ShellOpts::UserError in case of an error
69
+ def process
70
+ begin
71
+ @ast = Ast.parse(@grammar, @argv)
72
+ @idr = Idr.generate(self)
67
73
  rescue Ast::Parser::Error => ex
68
74
  raise UserError.new(ex.message)
69
75
  end
76
+ self
70
77
  end
71
78
 
72
79
  # Return an array representation of options and commands in the same order
@@ -1,3 +1,3 @@
1
1
  module Shellopts
2
- VERSION = "2.0.0.pre.8"
2
+ VERSION = "2.0.0.pre.9"
3
3
  end
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.pre.8
4
+ version: 2.0.0.pre.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen