clasp-ruby 0.16.1 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/clasp/aliases.rb +3 -3
- data/lib/clasp/arguments.rb +131 -2
- data/lib/clasp/version.rb +1 -1
- data/test/scratch/test_usage.rb +0 -2
- data/test/scratch/test_usage_from_DATA.rb +46 -0
- metadata +18 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 476b60beb87db0936ad2bf1d5562cd68d2ba41fe
|
4
|
+
data.tar.gz: ce781faefb3d24a1d431b48337fea7c1ebf2a0fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95926ccb787ca5b0dd1d6920783d103e0e4bf91b21c14763e9ae4c62ef872718fe41fd868c2e1d3fc7a5b764da5e831b02d73d0794486a3acabaa82edf2cf11f
|
7
|
+
data.tar.gz: e335964cf459fab293d7b9a790d7c66f34572844e8c5b544b0733283c5b37436ece225ddc5e845609dc422f7eb37ac90e928f59ad838bbdec29d7841e67e6e3d
|
data/lib/clasp/aliases.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Purpose: Alias classes
|
6
6
|
#
|
7
7
|
# Created: 25th October 2014
|
8
|
-
# Updated:
|
8
|
+
# Updated: 10th April 2019
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/CLASP.Ruby
|
11
11
|
#
|
@@ -257,7 +257,7 @@ def CLASP.Flag(name, options = {})
|
|
257
257
|
case k
|
258
258
|
when :alias
|
259
259
|
|
260
|
-
aliases = [ v ]
|
260
|
+
aliases = [ v ] if v
|
261
261
|
when :aliases
|
262
262
|
|
263
263
|
aliases = v unless aliases
|
@@ -328,7 +328,7 @@ def CLASP.Option(name, options = {})
|
|
328
328
|
case k
|
329
329
|
when :alias
|
330
330
|
|
331
|
-
aliases = [ v ]
|
331
|
+
aliases = [ v ] if v
|
332
332
|
when :aliases
|
333
333
|
|
334
334
|
aliases = v unless aliases
|
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: 10th April 2019
|
10
10
|
#
|
11
11
|
# Home: http://github.com/synesissoftware/CLASP.Ruby
|
12
12
|
#
|
@@ -46,6 +46,10 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
+
require File.join(File.dirname(__FILE__), 'aliases.rb')
|
50
|
+
|
51
|
+
require 'yaml'
|
52
|
+
|
49
53
|
=begin
|
50
54
|
=end
|
51
55
|
|
@@ -183,6 +187,131 @@ class Arguments
|
|
183
187
|
# Construction
|
184
188
|
|
185
189
|
public
|
190
|
+
|
191
|
+
# Loads an instance of the class, as specified by +source+, according to the given parameters
|
192
|
+
#
|
193
|
+
# See the documentation for the ::CLASP module for examples
|
194
|
+
#
|
195
|
+
# === Signature
|
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.
|
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>.
|
204
|
+
#
|
205
|
+
def self.load(argv, source, options = {})
|
206
|
+
|
207
|
+
options ||= {}
|
208
|
+
|
209
|
+
h = nil
|
210
|
+
|
211
|
+
case source
|
212
|
+
when ::IO
|
213
|
+
|
214
|
+
h = YAML.load(source.read)
|
215
|
+
when ::Hash
|
216
|
+
|
217
|
+
h = source
|
218
|
+
else
|
219
|
+
|
220
|
+
if source.respond_to?(:to_hash)
|
221
|
+
|
222
|
+
h = source.to_hash
|
223
|
+
else
|
224
|
+
|
225
|
+
raise TypeError, "#{self}.#{__method__}() 'source' argument must be a #{::Hash}, or an object implementing #{::IO}, or a type implementing to_hash'"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
aliases = []
|
230
|
+
|
231
|
+
_clasp = h['clasp'] or raise ArgumentError, "missing top-level 'clasp' element in load configuration"
|
232
|
+
::Hash === _clasp or raise ArgumentError, "top-level 'clasp' element must be a #{::Hash}"
|
233
|
+
|
234
|
+
_specs = (_clasp['arg-specs'] || _clasp['aliases']) or raise ArgumentError, "missing element 'clasp/arg-specs'"
|
235
|
+
::Array === _specs or raise ArgumentError, "top-level 'arg-specs' element must be a #{::Hash}"
|
236
|
+
|
237
|
+
_specs.each do |_spec|
|
238
|
+
|
239
|
+
case _spec
|
240
|
+
when ::Hash
|
241
|
+
|
242
|
+
# TODO: make a utility function and shrink all the following
|
243
|
+
|
244
|
+
_spec.each do |_arg_type, _details|
|
245
|
+
|
246
|
+
case _arg_type
|
247
|
+
when 'flag', :flag
|
248
|
+
|
249
|
+
_name = _details['name']
|
250
|
+
|
251
|
+
unless _name
|
252
|
+
|
253
|
+
warn "flag arg-spec missing required 'name' field"
|
254
|
+
else
|
255
|
+
|
256
|
+
_alias = _details['alias']
|
257
|
+
_aliases = _details['aliases']
|
258
|
+
_help = _details['help'] || _details['description']
|
259
|
+
|
260
|
+
aliases << CLASP.Flag(_name, alias: _alias, aliases: _aliases, help: _help)
|
261
|
+
end
|
262
|
+
when 'option', :option
|
263
|
+
|
264
|
+
_name = _details['name']
|
265
|
+
|
266
|
+
unless _name
|
267
|
+
|
268
|
+
warn "option arg-spec missing required 'name' field"
|
269
|
+
else
|
270
|
+
|
271
|
+
_alias = _details['alias']
|
272
|
+
_aliases = _details['aliases']
|
273
|
+
_default_value = _details['default_value'] || _details['default']
|
274
|
+
_help = _details['help'] || _details['description']
|
275
|
+
_required = _details['required']
|
276
|
+
_required_message = _details['required_message']
|
277
|
+
_values_range = _details['values_range'] || _details['values']
|
278
|
+
|
279
|
+
aliases << CLASP.Option(_name, alias: _alias, aliases: _aliases, default_value: _default_value, help: _help, required: _required, required_message: _required_message, values_range: _values_range)
|
280
|
+
end
|
281
|
+
when 'alias', :alias
|
282
|
+
|
283
|
+
_resolved = _details['resolved']
|
284
|
+
|
285
|
+
unless _resolved
|
286
|
+
|
287
|
+
warn "alias arg-spec missing required 'resolved' field"
|
288
|
+
else
|
289
|
+
|
290
|
+
_alias = _details['alias']
|
291
|
+
_aliases = _details['aliases']
|
292
|
+
|
293
|
+
unless _alias || _aliases
|
294
|
+
|
295
|
+
warn "alias arg-spec missing required 'alias' or 'aliases' field"
|
296
|
+
else
|
297
|
+
|
298
|
+
aliases << CLASP.Flag(_resolved, alias: _alias, aliases: _aliases)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
else
|
302
|
+
|
303
|
+
warn "unknown arg-type '#{_arg_type}' specified"
|
304
|
+
end
|
305
|
+
end
|
306
|
+
else
|
307
|
+
|
308
|
+
warn "non-#{::Hash} element in 'clasp/arg-specs': #{_spec} (of type #{_spec.class})"
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
self.new argv, aliases, options
|
313
|
+
end
|
314
|
+
|
186
315
|
# Constructs an instance of the class, according to the given parameters
|
187
316
|
#
|
188
317
|
# See the documentation for the ::CLASP module for examples
|
@@ -195,7 +324,7 @@ class Arguments
|
|
195
324
|
# - +options+:: An options hash, containing any of the following options.
|
196
325
|
#
|
197
326
|
# * *Options*:
|
198
|
-
# - +
|
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>.
|
199
328
|
#
|
200
329
|
def initialize(argv = ARGV, aliases = nil, options = {})
|
201
330
|
|
data/lib/clasp/version.rb
CHANGED
data/test/scratch/test_usage.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
|
7
|
+
Arguments = CLASP::Arguments.load(ARGV, DATA)
|
8
|
+
|
9
|
+
puts
|
10
|
+
puts '*' * 40
|
11
|
+
puts 'usage:'
|
12
|
+
puts
|
13
|
+
CLASP.show_usage(Arguments.aliases)
|
14
|
+
puts '*' * 40
|
15
|
+
|
16
|
+
puts 'version:'
|
17
|
+
puts
|
18
|
+
CLASP.show_version Arguments.aliases, version: [ 1, 2, 3 ]
|
19
|
+
puts '*' * 40
|
20
|
+
|
21
|
+
__END__
|
22
|
+
---
|
23
|
+
clasp:
|
24
|
+
arg-specs:
|
25
|
+
- flag:
|
26
|
+
name: --version
|
27
|
+
alias: -v
|
28
|
+
help: shows the program version and quits
|
29
|
+
- option:
|
30
|
+
name: --verbosity
|
31
|
+
help: the verbosity
|
32
|
+
values:
|
33
|
+
- silent
|
34
|
+
- quiet
|
35
|
+
- succinct
|
36
|
+
- chatty
|
37
|
+
- verbose
|
38
|
+
- alias:
|
39
|
+
resolved: --verbosity=succinct
|
40
|
+
aliases:
|
41
|
+
- --succinct
|
42
|
+
- -s
|
43
|
+
- alias:
|
44
|
+
resolved: --verbosity=verbose
|
45
|
+
alias: --verbose
|
46
|
+
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clasp-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.17.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Matt Wilson
|
@@ -14,39 +13,34 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: xqsr3
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0.30'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0.30'
|
30
|
-
description:
|
31
|
-
powerful
|
32
|
-
|
33
|
-
abstraction of command-line interpretation facilities. CLASP.Ruby is a Ruby port
|
34
|
-
of the popular CLASP (C/C++) library, and provides declarative specification of
|
35
|
-
command-line flags and options, aliasing, flag combination, UNIX de-facto standard
|
36
|
-
flag processing, and a number of utility functions for expressing usage and version
|
37
|
-
information.
|
38
|
-
|
39
|
-
'
|
27
|
+
description: |
|
28
|
+
Command-Line Argument Sorting and Parsing library that provides a powerful
|
29
|
+
abstraction of command-line interpretation facilities. CLASP.Ruby is a Ruby port of the popular CLASP (C/C++) library, and provides declarative specification of command-line flags and options, aliasing, flag combination, UNIX de-facto standard flag processing, and a number of utility functions for expressing usage and version information.
|
40
30
|
email: matthew@synesis.com.au
|
41
31
|
executables: []
|
42
32
|
extensions: []
|
43
33
|
extra_rdoc_files: []
|
44
34
|
files:
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
45
37
|
- examples/cr-example.rb
|
46
38
|
- examples/flag_and_option_aliases.md
|
47
39
|
- examples/flag_and_option_aliases.rb
|
48
40
|
- examples/show_usage_and_version.md
|
49
41
|
- examples/show_usage_and_version.rb
|
42
|
+
- lib/clasp-ruby.rb
|
43
|
+
- lib/clasp.rb
|
50
44
|
- lib/clasp/aliases.rb
|
51
45
|
- lib/clasp/arguments.rb
|
52
46
|
- lib/clasp/clasp.rb
|
@@ -54,18 +48,17 @@ files:
|
|
54
48
|
- lib/clasp/doc_.rb
|
55
49
|
- lib/clasp/old_module.rb
|
56
50
|
- lib/clasp/version.rb
|
57
|
-
- lib/clasp-ruby.rb
|
58
|
-
- lib/clasp.rb
|
59
51
|
- test/scratch/test_aliases.rb
|
60
52
|
- test/scratch/test_list_command_line.rb
|
61
53
|
- test/scratch/test_usage.rb
|
54
|
+
- test/scratch/test_usage_from_DATA.rb
|
62
55
|
- test/scratch/test_usage_with_duplicate_aliases.rb
|
56
|
+
- test/unit/tc_ARGV_rewrite.rb
|
63
57
|
- test/unit/tc_aliases.rb
|
64
58
|
- test/unit/tc_arguments_1.rb
|
65
59
|
- test/unit/tc_arguments_2.rb
|
66
60
|
- test/unit/tc_arguments_3.rb
|
67
61
|
- test/unit/tc_arguments_inspect.rb
|
68
|
-
- test/unit/tc_ARGV_rewrite.rb
|
69
62
|
- test/unit/tc_cli.rb
|
70
63
|
- test/unit/tc_defaults_1.rb
|
71
64
|
- test/unit/tc_examples_Arguments.rb
|
@@ -73,31 +66,28 @@ files:
|
|
73
66
|
- test/unit/tc_option_required.rb
|
74
67
|
- test/unit/tc_usage.rb
|
75
68
|
- test/unit/ts_all.rb
|
76
|
-
- README.md
|
77
|
-
- LICENSE
|
78
69
|
homepage: http://github.com/synesissoftware/CLASP.Ruby
|
79
70
|
licenses:
|
80
|
-
- BSD
|
71
|
+
- BSD-3-Clause
|
72
|
+
metadata: {}
|
81
73
|
post_install_message:
|
82
74
|
rdoc_options: []
|
83
75
|
require_paths:
|
84
76
|
- lib
|
85
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
78
|
requirements:
|
88
|
-
- -
|
79
|
+
- - ">="
|
89
80
|
- !ruby/object:Gem::Version
|
90
81
|
version: 1.9.3
|
91
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
83
|
requirements:
|
94
|
-
- -
|
84
|
+
- - ">="
|
95
85
|
- !ruby/object:Gem::Version
|
96
86
|
version: '0'
|
97
87
|
requirements: []
|
98
88
|
rubyforge_project:
|
99
|
-
rubygems_version:
|
89
|
+
rubygems_version: 2.6.11
|
100
90
|
signing_key:
|
101
|
-
specification_version:
|
91
|
+
specification_version: 4
|
102
92
|
summary: CLASP.Ruby
|
103
93
|
test_files: []
|