clasp-ruby 0.18.2 → 0.19.0
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 +4 -4
- data/lib/clasp/arguments.rb +49 -33
- data/lib/clasp/cli.rb +5 -5
- data/lib/clasp/specifications.rb +85 -11
- data/lib/clasp/version.rb +2 -2
- data/test/unit/tc_option_value_aliases.rb +74 -0
- data/test/unit/tc_specifications.rb +8 -61
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95ce67e26d5789cde25d8fd230f49933751f0c60
|
4
|
+
data.tar.gz: c8be483da241ea331f967af810dcb50338561886
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77474bb5bb8a963d0649888750eb7d563e8549ac0d81fffd08e938091d5d91d9d32e1a21744190b69787cca8af138696aaf4aee8547e409f6f28cd71444a6191
|
7
|
+
data.tar.gz: 38a535bc60563b48eff9df3bdf28516b99caea46505f7b2fe7b464ada7fdb5273a3921be571ad020214fb8c4bf79d77eed44c63e30cd0636f1b1b19284c10b56
|
data/lib/clasp/arguments.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# CLASP.Ruby
|
7
7
|
#
|
8
8
|
# Created: 14th February 2014
|
9
|
-
# Updated:
|
9
|
+
# Updated: 13th April 2019
|
10
10
|
#
|
11
11
|
# Home: http://github.com/synesissoftware/CLASP.Ruby
|
12
12
|
#
|
@@ -63,9 +63,9 @@ class Arguments
|
|
63
63
|
|
64
64
|
#:stopdoc:
|
65
65
|
private
|
66
|
-
class FlagArgument
|
66
|
+
class FlagArgument # :nodoc: all
|
67
67
|
|
68
|
-
|
68
|
+
# :nodoc:
|
69
69
|
def initialize(arg, given_index, given_name, resolved_name, argument_alias, given_hyphens, given_label, extras)
|
70
70
|
|
71
71
|
@arg = arg
|
@@ -86,13 +86,13 @@ class Arguments
|
|
86
86
|
attr_reader :name
|
87
87
|
attr_reader :extras
|
88
88
|
|
89
|
-
|
89
|
+
# :nodoc:
|
90
90
|
def to_s
|
91
91
|
|
92
92
|
@name
|
93
93
|
end
|
94
94
|
|
95
|
-
|
95
|
+
# :nodoc:
|
96
96
|
def eql?(rhs)
|
97
97
|
|
98
98
|
return false if rhs.nil?
|
@@ -103,7 +103,7 @@ class Arguments
|
|
103
103
|
false
|
104
104
|
end
|
105
105
|
|
106
|
-
|
106
|
+
# :nodoc:
|
107
107
|
def ==(rhs)
|
108
108
|
|
109
109
|
return false if rhs.nil?
|
@@ -114,16 +114,16 @@ class Arguments
|
|
114
114
|
eql? rhs
|
115
115
|
end
|
116
116
|
|
117
|
-
|
117
|
+
# :nodoc:
|
118
118
|
def hash
|
119
119
|
|
120
120
|
@arg.hash
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
class OptionArgument
|
124
|
+
class OptionArgument # :nodoc: all
|
125
125
|
|
126
|
-
|
126
|
+
# :nodoc:
|
127
127
|
def initialize(arg, given_index, given_name, resolved_name, argument_alias, given_hyphens, given_label, value, extras)
|
128
128
|
|
129
129
|
@arg = arg
|
@@ -146,7 +146,7 @@ class Arguments
|
|
146
146
|
attr_reader :value
|
147
147
|
attr_reader :extras
|
148
148
|
|
149
|
-
|
149
|
+
# :nodoc:
|
150
150
|
def eql?(rhs)
|
151
151
|
|
152
152
|
return false if rhs.nil?
|
@@ -157,7 +157,7 @@ class Arguments
|
|
157
157
|
false
|
158
158
|
end
|
159
159
|
|
160
|
-
|
160
|
+
# :nodoc:
|
161
161
|
def ==(rhs)
|
162
162
|
|
163
163
|
return false if rhs.nil?
|
@@ -168,13 +168,13 @@ class Arguments
|
|
168
168
|
eql? rhs
|
169
169
|
end
|
170
170
|
|
171
|
-
|
171
|
+
# :nodoc:
|
172
172
|
def hash
|
173
173
|
|
174
174
|
@arg.hash
|
175
175
|
end
|
176
176
|
|
177
|
-
|
177
|
+
# :nodoc:
|
178
178
|
def to_s
|
179
179
|
|
180
180
|
"#{name}=#{value}"
|
@@ -194,15 +194,31 @@ class Arguments
|
|
194
194
|
#
|
195
195
|
# === Signature
|
196
196
|
#
|
197
|
-
# * *Parameters
|
198
|
-
# - +argv+:: (+Array+) The arguments array. May not be +nil+. Defaults to +ARGV
|
199
|
-
# - +source+:: (+Hash+, +IO+) The arguments specification, either as a Hash or an instance of an IO-implementing type containing a YAML specification
|
200
|
-
# - +options+:: An options hash, containing any of the following options
|
197
|
+
# * *Parameters:*
|
198
|
+
# - +argv+:: (+Array+) The arguments array. May not be +nil+. Defaults to +ARGV+
|
199
|
+
# - +source+:: (+Hash+, +IO+) The arguments specification, either as a Hash or an instance of an IO-implementing type containing a YAML specification
|
200
|
+
# - +options+:: An options hash, containing any of the following options
|
201
201
|
#
|
202
|
-
# * *Options
|
203
|
-
# - +mutate_argv:+:: (+Boolean+) Determines if the library should mutate +argv+. Defaults to +true+. This is essential when using CLASP in conjunction with <tt>$\<</tt
|
202
|
+
# * *Options:*
|
203
|
+
# - +mutate_argv:+:: (+Boolean+) Determines if the library should mutate +argv+. Defaults to +true+. This is essential when using CLASP in conjunction with <tt>$\<</tt>
|
204
204
|
#
|
205
|
-
def self.load(argv, source, options = {})
|
205
|
+
def self.load(argv, source, options = {}) # :yields: An instance of +CLASP::Arguments+
|
206
|
+
|
207
|
+
options ||= {}
|
208
|
+
|
209
|
+
specs = load_specifications(source, options)
|
210
|
+
|
211
|
+
self.new argv, specs, options
|
212
|
+
end
|
213
|
+
|
214
|
+
# Loads the specifications as specified by +source+, according to the given parameters
|
215
|
+
#
|
216
|
+
# === Signature
|
217
|
+
#
|
218
|
+
# * *Parameters:*
|
219
|
+
# - +source+:: (+Hash+, +IO+) The arguments specification, either as a Hash or an instance of an IO-implementing type containing a YAML specification
|
220
|
+
# - +options+:: An options hash, containing any of the following options
|
221
|
+
def self.load_specifications(source, options = {}) # :yields: An array of specification instances
|
206
222
|
|
207
223
|
options ||= {}
|
208
224
|
|
@@ -226,7 +242,7 @@ class Arguments
|
|
226
242
|
end
|
227
243
|
end
|
228
244
|
|
229
|
-
|
245
|
+
specs = []
|
230
246
|
|
231
247
|
_clasp = h['clasp'] or raise ArgumentError, "missing top-level 'clasp' element in load configuration"
|
232
248
|
::Hash === _clasp or raise ArgumentError, "top-level 'clasp' element must be a #{::Hash}"
|
@@ -257,7 +273,7 @@ class Arguments
|
|
257
273
|
_aliases = _details['aliases']
|
258
274
|
_help = _details['help'] || _details['description']
|
259
275
|
|
260
|
-
|
276
|
+
specs << CLASP.Flag(_name, alias: _alias, aliases: _aliases, help: _help)
|
261
277
|
end
|
262
278
|
when 'option', :option
|
263
279
|
|
@@ -276,7 +292,7 @@ class Arguments
|
|
276
292
|
_required_message = _details['required_message']
|
277
293
|
_values_range = _details['values_range'] || _details['values']
|
278
294
|
|
279
|
-
|
295
|
+
specs << CLASP.Option(_name, alias: _alias, aliases: _aliases, default_value: _default_value, help: _help, required: _required, required_message: _required_message, values_range: _values_range)
|
280
296
|
end
|
281
297
|
when 'alias', :alias
|
282
298
|
|
@@ -295,7 +311,7 @@ class Arguments
|
|
295
311
|
warn "alias specification missing required 'alias' or 'aliases' field"
|
296
312
|
else
|
297
313
|
|
298
|
-
|
314
|
+
specs << CLASP.Flag(_resolved, alias: _alias, aliases: _aliases)
|
299
315
|
end
|
300
316
|
end
|
301
317
|
else
|
@@ -309,7 +325,7 @@ class Arguments
|
|
309
325
|
end
|
310
326
|
end
|
311
327
|
|
312
|
-
|
328
|
+
specs
|
313
329
|
end
|
314
330
|
|
315
331
|
# Constructs an instance of the class, according to the given parameters
|
@@ -318,13 +334,13 @@ class Arguments
|
|
318
334
|
#
|
319
335
|
# === Signature
|
320
336
|
#
|
321
|
-
# * *Parameters
|
322
|
-
# - +argv+:: (+Array+) The arguments array. May not be +nil+. Defaults to +ARGV
|
323
|
-
# - +specifications+:: (+Array+) The specifications array. Defaults to +nil+. If none supplied, no aliasing will be performed
|
324
|
-
# - +options+:: An options hash, containing any of the following options
|
337
|
+
# * *Parameters:*
|
338
|
+
# - +argv+:: (+Array+) The arguments array. May not be +nil+. Defaults to +ARGV+
|
339
|
+
# - +specifications+:: (+Array+) The specifications array. Defaults to +nil+. If none supplied, no aliasing will be performed
|
340
|
+
# - +options+:: An options hash, containing any of the following options
|
325
341
|
#
|
326
|
-
# * *Options
|
327
|
-
# - +mutate_argv:+:: (+Boolean+) Determines if the library should mutate +argv+. Defaults to +true+. This is essential when using CLASP in conjunction with <tt>$\<</tt
|
342
|
+
# * *Options:*
|
343
|
+
# - +mutate_argv:+:: (+Boolean+) Determines if the library should mutate +argv+. Defaults to +true+. This is essential when using CLASP in conjunction with <tt>$\<</tt>
|
328
344
|
#
|
329
345
|
def initialize(argv = ARGV, specifications = nil, options = {})
|
330
346
|
|
@@ -598,7 +614,7 @@ class Arguments
|
|
598
614
|
#
|
599
615
|
# === Signature
|
600
616
|
#
|
601
|
-
# * *Parameters
|
617
|
+
# * *Parameters:*
|
602
618
|
# - +id+:: (String, CLASP::Flag) The name of a flag, or the flag itself
|
603
619
|
def find_flag(id)
|
604
620
|
|
@@ -615,7 +631,7 @@ class Arguments
|
|
615
631
|
#
|
616
632
|
# === Signature
|
617
633
|
#
|
618
|
-
# * *
|
634
|
+
# * *Parameter:*
|
619
635
|
# - +id+:: (String, CLASP::Flag) The name of a option, or the option itself
|
620
636
|
def find_option(id)
|
621
637
|
|
data/lib/clasp/cli.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Command-line interface
|
6
6
|
#
|
7
7
|
# Created: 27th July 2015
|
8
|
-
# Updated:
|
8
|
+
# Updated: 12th April 2019
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/CLASP.Ruby
|
11
11
|
#
|
@@ -113,11 +113,11 @@ end # module CLI_helpers_
|
|
113
113
|
#
|
114
114
|
# === Signature
|
115
115
|
#
|
116
|
-
# * *Parameters
|
116
|
+
# * *Parameters:*
|
117
117
|
# - +specifications+:: (+Array+) The arguments array. May not be +nil+. Defaults to +ARGV+.
|
118
118
|
# - +options+:: An options hash, containing any of the following options.
|
119
119
|
#
|
120
|
-
# * *Options
|
120
|
+
# * *Options:*
|
121
121
|
# - +:exit+:: a program exit code; <tt>exit()</tt> not called if not specified (or +nil+).
|
122
122
|
# - +:program_name+:: program name; inferred from <tt>$0</tt> if not specified.
|
123
123
|
# - +:stream+:: output stream; <tt>$stdout</tt> if not specified.
|
@@ -254,11 +254,11 @@ end
|
|
254
254
|
#
|
255
255
|
# === Signature
|
256
256
|
#
|
257
|
-
# * *Parameters
|
257
|
+
# * *Parameters:*
|
258
258
|
# - +specifications+:: (+Array+) The arguments array. May not be +nil+. Defaults to +ARGV+.
|
259
259
|
# - +options+:: An options hash, containing any of the following options.
|
260
260
|
#
|
261
|
-
# * *Options
|
261
|
+
# * *Options:*
|
262
262
|
# - +:exit+:: a program exit code; <tt>exit()</tt> not called if not specified (or +nil+).
|
263
263
|
# - +:program_name+:: program name; inferred from <tt>$0</tt> if not specified.
|
264
264
|
# - +:stream+:: output stream; <tt>$stdout</tt> if not specified.
|
data/lib/clasp/specifications.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Argument specification classes
|
6
6
|
#
|
7
7
|
# Created: 25th October 2014
|
8
|
-
# Updated:
|
8
|
+
# Updated: 13th April 2019
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/CLASP.Ruby
|
11
11
|
#
|
@@ -65,10 +65,10 @@ class FlagSpecification
|
|
65
65
|
# === Signature
|
66
66
|
#
|
67
67
|
# * *Parameters*
|
68
|
-
# - +name+:: (+String+) The name, or long-form, of the flag
|
69
|
-
# - +aliases+:: (+Array+) 0 or more strings specifying short-form or option-value aliases
|
70
|
-
# - +help+:: (+String+) The help string, which may be +nil
|
71
|
-
# - +extras+:: An application-defined additional parameter. If +nil+, it is assigned an empty +Hash
|
68
|
+
# - +name+:: (+String+) The name, or long-form, of the flag
|
69
|
+
# - +aliases+:: (+Array+) 0 or more strings specifying short-form or option-value aliases
|
70
|
+
# - +help+:: (+String+) The help string, which may be +nil+
|
71
|
+
# - +extras+:: An application-defined additional parameter. If +nil+, it is assigned an empty +Hash+
|
72
72
|
def initialize(name, aliases, help, extras = nil)
|
73
73
|
|
74
74
|
@name = name
|
@@ -92,6 +92,41 @@ class FlagSpecification
|
|
92
92
|
"{#{name}; aliases=#{aliases.join(', ')}; help='#{help}'; extras=#{extras}}"
|
93
93
|
end
|
94
94
|
|
95
|
+
def eql? rhs # :nodoc:
|
96
|
+
|
97
|
+
case rhs
|
98
|
+
when self.class
|
99
|
+
|
100
|
+
;
|
101
|
+
else
|
102
|
+
|
103
|
+
return false
|
104
|
+
end
|
105
|
+
|
106
|
+
return false unless name == rhs.name
|
107
|
+
return false unless aliases == rhs.aliases
|
108
|
+
return false unless help == rhs.help
|
109
|
+
return false unless extras == rhs.extras
|
110
|
+
|
111
|
+
return true
|
112
|
+
end
|
113
|
+
|
114
|
+
# Compares instance against another FlagSpecification or against a name (String)
|
115
|
+
def == rhs
|
116
|
+
|
117
|
+
case rhs
|
118
|
+
when self.class
|
119
|
+
|
120
|
+
return self.eql? rhs
|
121
|
+
when String
|
122
|
+
|
123
|
+
return name == rhs
|
124
|
+
else
|
125
|
+
|
126
|
+
false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
95
130
|
private
|
96
131
|
@@Help_ = self.new('--help', [], 'shows this help and terminates')
|
97
132
|
@@Version_ = self.new('--version', [], 'shows version and terminates')
|
@@ -126,11 +161,11 @@ class OptionSpecification
|
|
126
161
|
# === Signature
|
127
162
|
#
|
128
163
|
# * *Parameters*
|
129
|
-
# - +name+:: (+String+) The name, or long-form, of the option
|
130
|
-
# - +aliases+:: (+Array+) 0 or more strings specifying short-form or option-value aliases
|
131
|
-
# - +help+:: (+String+) The help string, which may be +nil
|
132
|
-
# - +values_range+:: (+Array+) 0 or more strings specifying values supported by the option
|
133
|
-
# - +default_value+:: (+String+) The default value of the option. May be +nil
|
164
|
+
# - +name+:: (+String+) The name, or long-form, of the option
|
165
|
+
# - +aliases+:: (+Array+) 0 or more strings specifying short-form or option-value aliases
|
166
|
+
# - +help+:: (+String+) The help string, which may be +nil+
|
167
|
+
# - +values_range+:: (+Array+) 0 or more strings specifying values supported by the option
|
168
|
+
# - +default_value+:: (+String+) The default value of the option. May be +nil+
|
134
169
|
# - +required+:: [boolean] Whether the option is required. May be
|
135
170
|
# +nil+
|
136
171
|
# - +required_message+:: [::String] Message to be used when reporting
|
@@ -139,7 +174,7 @@ class OptionSpecification
|
|
139
174
|
# usage". If begins with the nul character ("\0"), then is used in
|
140
175
|
# the place of the <option-name> and placed into the rest of the
|
141
176
|
# standard form message
|
142
|
-
# - +extras+:: An application-defined additional parameter. If +nil+, it is assigned an empty +Hash
|
177
|
+
# - +extras+:: An application-defined additional parameter. If +nil+, it is assigned an empty +Hash+
|
143
178
|
def initialize(name, aliases, help, values_range, default_value, required, required_message, extras = nil)
|
144
179
|
|
145
180
|
@name = name
|
@@ -195,6 +230,45 @@ class OptionSpecification
|
|
195
230
|
|
196
231
|
"{#{name}; aliases=#{aliases.join(', ')}; values_range=[ #{values_range.join(', ')} ]; default_value='#{default_value}'; help='#{help}'; required?=#{required?}; extras=#{extras}}"
|
197
232
|
end
|
233
|
+
|
234
|
+
def eql? rhs # :nodoc:
|
235
|
+
|
236
|
+
case rhs
|
237
|
+
when self.class
|
238
|
+
|
239
|
+
;
|
240
|
+
else
|
241
|
+
|
242
|
+
return false
|
243
|
+
end
|
244
|
+
|
245
|
+
return false unless name == rhs.name
|
246
|
+
return false unless aliases == rhs.aliases
|
247
|
+
return false unless help == rhs.help
|
248
|
+
return false unless values_range == rhs.values_range
|
249
|
+
return false unless default_value == rhs.default_value
|
250
|
+
return false unless required == rhs.required
|
251
|
+
return false unless required_message == rhs.required_message
|
252
|
+
return false unless extras == rhs.extras
|
253
|
+
|
254
|
+
return true
|
255
|
+
end
|
256
|
+
|
257
|
+
# Compares instance against another OptionSpecification or against a name (String)
|
258
|
+
def == rhs
|
259
|
+
|
260
|
+
case rhs
|
261
|
+
when self.class
|
262
|
+
|
263
|
+
return self.eql? rhs
|
264
|
+
when String
|
265
|
+
|
266
|
+
return name == rhs
|
267
|
+
else
|
268
|
+
|
269
|
+
false
|
270
|
+
end
|
271
|
+
end
|
198
272
|
end
|
199
273
|
|
200
274
|
# A class that represents an explicit alias for a flag or an option
|
data/lib/clasp/version.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Version for CLASP.Ruby library
|
6
6
|
#
|
7
7
|
# Created: 16th November 2014
|
8
|
-
# Updated:
|
8
|
+
# Updated: 13th April 2019
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/CLASP.Ruby
|
11
11
|
#
|
@@ -51,7 +51,7 @@
|
|
51
51
|
module CLASP
|
52
52
|
|
53
53
|
# Current version of the CLASP.Ruby library
|
54
|
-
VERSION = '0.
|
54
|
+
VERSION = '0.19.0'
|
55
55
|
|
56
56
|
private
|
57
57
|
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class Test_OptionValueAliases_1 < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_option_with_two_flag_specifications
|
12
|
+
|
13
|
+
specifications = [
|
14
|
+
|
15
|
+
CLASP.Flag('--action=list', alias: '-l'),
|
16
|
+
CLASP.Flag('--action=change', alias: '-c'),
|
17
|
+
CLASP.Option('--action', alias: '-a'),
|
18
|
+
]
|
19
|
+
|
20
|
+
# With no arguments
|
21
|
+
begin
|
22
|
+
|
23
|
+
argv = []
|
24
|
+
args = CLASP::Arguments.new argv, specifications
|
25
|
+
|
26
|
+
assert_equal 0, args.flags.size
|
27
|
+
assert_equal 0, args.options.size
|
28
|
+
assert_equal 0, args.values.size
|
29
|
+
end
|
30
|
+
|
31
|
+
# With option
|
32
|
+
begin
|
33
|
+
|
34
|
+
argv = %w{ --action=action1 }
|
35
|
+
args = CLASP::Arguments.new argv, specifications
|
36
|
+
|
37
|
+
assert_equal 0, args.flags.size
|
38
|
+
assert_equal 1, args.options.size
|
39
|
+
assert_equal 0, args.values.size
|
40
|
+
|
41
|
+
assert_equal '--action', args.options[0].name
|
42
|
+
assert_equal 'action1', args.options[0].value
|
43
|
+
end
|
44
|
+
|
45
|
+
# With option alias
|
46
|
+
begin
|
47
|
+
|
48
|
+
argv = %w{ -a action2 }
|
49
|
+
args = CLASP::Arguments.new argv, specifications
|
50
|
+
|
51
|
+
assert_equal 0, args.flags.size
|
52
|
+
assert_equal 1, args.options.size
|
53
|
+
assert_equal 0, args.values.size
|
54
|
+
|
55
|
+
assert_equal '--action', args.options[0].name
|
56
|
+
assert_equal 'action2', args.options[0].value
|
57
|
+
end
|
58
|
+
|
59
|
+
# With flag alias
|
60
|
+
begin
|
61
|
+
|
62
|
+
argv = %w{ -c }
|
63
|
+
args = CLASP::Arguments.new argv, specifications
|
64
|
+
|
65
|
+
assert_equal 0, args.flags.size
|
66
|
+
assert_equal 1, args.options.size
|
67
|
+
assert_equal 0, args.values.size
|
68
|
+
|
69
|
+
assert_equal '--action', args.options[0].name
|
70
|
+
assert_equal 'change', args.options[0].value
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
4
4
|
|
@@ -8,68 +8,15 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_Specifications_1 < Test::Unit::TestCase
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_simple_Flag
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
CLASP.Flag('--action=list', alias: '-l'),
|
16
|
-
CLASP.Flag('--action=change', alias: '-c'),
|
17
|
-
CLASP.Option('--action', alias: '-a'),
|
18
|
-
]
|
19
|
-
|
20
|
-
# With no arguments
|
21
|
-
begin
|
22
|
-
|
23
|
-
argv = []
|
24
|
-
args = CLASP::Arguments.new argv, specifications
|
25
|
-
|
26
|
-
assert_equal 0, args.flags.size
|
27
|
-
assert_equal 0, args.options.size
|
28
|
-
assert_equal 0, args.values.size
|
29
|
-
end
|
30
|
-
|
31
|
-
# With option
|
32
|
-
begin
|
33
|
-
|
34
|
-
argv = %w{ --action=action1 }
|
35
|
-
args = CLASP::Arguments.new argv, specifications
|
36
|
-
|
37
|
-
assert_equal 0, args.flags.size
|
38
|
-
assert_equal 1, args.options.size
|
39
|
-
assert_equal 0, args.values.size
|
40
|
-
|
41
|
-
assert_equal '--action', args.options[0].name
|
42
|
-
assert_equal 'action1', args.options[0].value
|
43
|
-
end
|
44
|
-
|
45
|
-
# With option alias
|
46
|
-
begin
|
47
|
-
|
48
|
-
argv = %w{ -a action2 }
|
49
|
-
args = CLASP::Arguments.new argv, specifications
|
50
|
-
|
51
|
-
assert_equal 0, args.flags.size
|
52
|
-
assert_equal 1, args.options.size
|
53
|
-
assert_equal 0, args.values.size
|
54
|
-
|
55
|
-
assert_equal '--action', args.options[0].name
|
56
|
-
assert_equal 'action2', args.options[0].value
|
57
|
-
end
|
58
|
-
|
59
|
-
# With flag alias
|
60
|
-
begin
|
61
|
-
|
62
|
-
argv = %w{ -c }
|
63
|
-
args = CLASP::Arguments.new argv, specifications
|
64
|
-
|
65
|
-
assert_equal 0, args.flags.size
|
66
|
-
assert_equal 1, args.options.size
|
67
|
-
assert_equal 0, args.values.size
|
68
|
-
|
69
|
-
assert_equal '--action', args.options[0].name
|
70
|
-
assert_equal 'change', args.options[0].value
|
71
|
-
end
|
13
|
+
flag_debug = CLASP.Flag('--name')
|
14
|
+
flag_logged = CLASP.Flag('--logged')
|
72
15
|
|
16
|
+
assert_equal flag_debug, flag_debug
|
17
|
+
assert_equal flag_debug, '--name'
|
18
|
+
assert_not_equal flag_logged, flag_debug
|
73
19
|
end
|
74
20
|
end
|
75
21
|
|
22
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clasp-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Wilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xqsr3
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- test/unit/tc_examples_Arguments.rb
|
65
65
|
- test/unit/tc_extras.rb
|
66
66
|
- test/unit/tc_option_required.rb
|
67
|
+
- test/unit/tc_option_value_aliases.rb
|
67
68
|
- test/unit/tc_specifications.rb
|
68
69
|
- test/unit/tc_usage.rb
|
69
70
|
- test/unit/ts_all.rb
|