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 +4 -4
- data/lib/shellopts/args.rb +4 -6
- data/lib/shellopts/argument_type.rb +3 -3
- data/lib/shellopts/interpreter.rb +1 -1
- data/lib/shellopts/version.rb +1 -1
- data/lib/shellopts.rb +2 -1
- data/main +8 -8
- 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: c3b7401560ce40fd21fcbc1e1c666464f2b01a4da8a93a4ec32010aa480bb8aa
|
4
|
+
data.tar.gz: f998e1ab794ab4e1b711d72e7d4e6820304ab6733bc9ae9d1fa137ab4323c633
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9b7856eb14fa2166bbc80dcace1724ee1a6499e93ce63f4971bdc9c4b27df4e5b26bc9d147a728de059d6e25d4e561a24aff39e2add47ca9a29aa5ad186b88f
|
7
|
+
data.tar.gz: 2cf14edab9a3cbb43ed3991596574e372af6527736031bd04626fb202cdf739b46565cee5c19cc67e46573c570651b7290852728958b075eeabe0df4f5197b0b
|
data/lib/shellopts/args.rb
CHANGED
@@ -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
|
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
|
18
|
-
#
|
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)
|
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
|
data/lib/shellopts/version.rb
CHANGED
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.
|
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
|
-
|
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
|
|