libclimate-ruby 0.5.4 → 0.6.1
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/libclimate/climate.rb +68 -8
- data/lib/libclimate/version.rb +2 -2
- data/test/unit/tc_abort.rb +1 -2
- data/test/unit/tc_infer_version.rb +61 -0
- data/test/unit/tc_minimal.rb +4 -2
- data/test/unit/tc_minimal_CLASP.rb +2 -3
- data/test/unit/tc_test_aliases.rb +5 -6
- data/test/unit/tc_with_blocks.rb +2 -3
- data/test/unit/tc_with_blocks_CLASP.rb +2 -3
- data/test/unit/ts_all.rb +1 -1
- 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: 24a39166bed4017b6995568774ae097912ba87b6
|
4
|
+
data.tar.gz: 8fa2bfc9913468c918e6ebb9d60943de2c4eeeb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f870554b875e6cf86197a64425808f1c4b82e5d004bad13408056b2e67abcda35e3d858e21b83551965ba865fa300e2848a5db1544bebb84723e12aa75e80c4
|
7
|
+
data.tar.gz: 3b603573a811bc14318b0d329f751b45aaec215c80d8f84b6a40abe543619e72045d7f487c40191b2e60df6988df1b63887996f51f0ecb0c7e55ebf8f0401910
|
data/lib/libclimate/climate.rb
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
# Purpose: Definition of the ::LibCLImate::Climate class
|
6
6
|
#
|
7
7
|
# Created: 13th July 2015
|
8
|
-
# Updated:
|
8
|
+
# Updated: 16th March 2017
|
9
9
|
#
|
10
10
|
# Home: http://github.com/synesissoftware/libCLImate.Ruby
|
11
11
|
#
|
12
12
|
# Author: Matthew Wilson
|
13
13
|
#
|
14
|
-
# Copyright (c) 2015-
|
14
|
+
# Copyright (c) 2015-2017, Matthew Wilson and Synesis Software
|
15
15
|
# All rights reserved.
|
16
16
|
#
|
17
17
|
# Redistribution and use in source and binary forms, with or without
|
@@ -147,6 +147,26 @@ class Climate
|
|
147
147
|
|
148
148
|
def show_version_
|
149
149
|
|
150
|
+
ver = version || []
|
151
|
+
|
152
|
+
if ver.empty?
|
153
|
+
|
154
|
+
if defined? PROGRAM_VER_MAJOR
|
155
|
+
|
156
|
+
ver << PROGRAM_VER_MAJOR
|
157
|
+
|
158
|
+
if defined? PROGRAM_VER_MINOR
|
159
|
+
|
160
|
+
ver << PROGRAM_VER_MINOR
|
161
|
+
|
162
|
+
if defined? PROGRAM_VERSION_REVISION
|
163
|
+
|
164
|
+
ver << PROGRAM_VER_REVISION
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
150
170
|
CLASP.show_version aliases, stream: stdout, program_name: program_name, version: version, exit: exit_on_usage ? 0 : nil
|
151
171
|
end
|
152
172
|
|
@@ -225,6 +245,8 @@ class Climate
|
|
225
245
|
# - +argv+:: The array of arguments; defaults to <tt>ARGV</tt>
|
226
246
|
#
|
227
247
|
# * *Returns*:
|
248
|
+
# an instance of a type derived from +::Hash+ with the additional
|
249
|
+
# attributes +flags+, +options+, +values+, and +argv+.
|
228
250
|
#
|
229
251
|
def run argv = ARGV
|
230
252
|
|
@@ -281,6 +303,7 @@ class Climate
|
|
281
303
|
|
282
304
|
case ex
|
283
305
|
when ::Hash
|
306
|
+
|
284
307
|
if ex.has_key? :handle
|
285
308
|
|
286
309
|
ex[:handle].call(f, al)
|
@@ -337,6 +360,7 @@ class Climate
|
|
337
360
|
|
338
361
|
case ex
|
339
362
|
when ::Hash
|
363
|
+
|
340
364
|
if ex.has_key? :handle
|
341
365
|
|
342
366
|
ex[:handle].call(o, al)
|
@@ -383,6 +407,11 @@ class Climate
|
|
383
407
|
self[:values]
|
384
408
|
end
|
385
409
|
|
410
|
+
results.define_singleton_method(:argv) do
|
411
|
+
|
412
|
+
argv
|
413
|
+
end
|
414
|
+
|
386
415
|
results
|
387
416
|
end
|
388
417
|
|
@@ -444,6 +473,8 @@ class Climate
|
|
444
473
|
# - +:extras+::
|
445
474
|
def add_flag(name, options={}, &block)
|
446
475
|
|
476
|
+
::Xqsr3::Quality::ParameterChecking.check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
|
477
|
+
|
447
478
|
aliases << CLASP.Flag(name, **options, &block)
|
448
479
|
end
|
449
480
|
|
@@ -457,6 +488,8 @@ class Climate
|
|
457
488
|
# - +:extras+::
|
458
489
|
def add_option(name, options={}, &block)
|
459
490
|
|
491
|
+
::Xqsr3::Quality::ParameterChecking.check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
|
492
|
+
|
460
493
|
aliases << CLASP.Option(name, **options, &block)
|
461
494
|
end
|
462
495
|
|
@@ -465,17 +498,44 @@ class Climate
|
|
465
498
|
# === Signature
|
466
499
|
#
|
467
500
|
# * *Parameters*
|
468
|
-
# - +name+:: The flag name
|
469
|
-
# - +
|
501
|
+
# - +name+:: The flag/option name or the valued option
|
502
|
+
# - +aliases+:: One or more aliases
|
503
|
+
#
|
504
|
+
# === Examples
|
505
|
+
#
|
506
|
+
# ==== Alias(es) of a flag (single statement)
|
507
|
+
#
|
508
|
+
# +climate.add_flag('--mark-missing', alias: '-x')+
|
509
|
+
#
|
510
|
+
# +climate.add_flag('--absolute-path', aliases: [ '-abs', '-p' ])+
|
511
|
+
#
|
512
|
+
# ==== Alias(es) of a flag (multiple statements)
|
513
|
+
#
|
514
|
+
# +climate.add_flag('--mark-missing')+
|
515
|
+
# +climate.add_alias('--mark-missing', '-x')+
|
516
|
+
#
|
517
|
+
# +climate.add_flag('--absolute-path')+
|
518
|
+
# +climate.add_alias('--absolute-path', '-abs', '-p')+
|
519
|
+
#
|
520
|
+
# ==== Alias(es) of an option (single statement)
|
521
|
+
#
|
522
|
+
# +climate.add_option('--add-patterns', alias: '-p')+
|
523
|
+
#
|
524
|
+
# ==== Alias(es) of an option (multiple statements)
|
525
|
+
#
|
526
|
+
# +climate.add_option('--add-patterns')+
|
527
|
+
# +climate.add_alias('--add-patterns', '-p')+
|
528
|
+
#
|
529
|
+
# ==== Alias of a valued option (which has to be multiple statements)
|
530
|
+
#
|
531
|
+
# +climate.add_option('--verbosity')+
|
532
|
+
# +climate.add_alias('--verbosity=succinct', '-s')+
|
533
|
+
# +climate.add_alias('--verbosity=verbose', '-v')+
|
470
534
|
def add_alias(name, *aliases)
|
471
535
|
|
472
536
|
::Xqsr3::Quality::ParameterChecking.check_parameter name, 'name', allow_nil: false, types: [ ::String, ::Symbol ]
|
473
537
|
raise ArgumentError, "must supply at least one alias" if aliases.empty?
|
474
538
|
|
475
|
-
=begin
|
476
|
-
klass = CLASP::Option
|
477
|
-
=end
|
478
|
-
|
479
539
|
self.aliases << CLASP.Option(name, aliases: aliases)
|
480
540
|
end
|
481
541
|
end # class Climate
|
data/lib/libclimate/version.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# Purpose: Version for libclimate.Ruby library
|
5
5
|
#
|
6
6
|
# Created: 13th July 2015
|
7
|
-
# Updated:
|
7
|
+
# Updated: 5th July 2016
|
8
8
|
#
|
9
9
|
# Home: http://github.com/synesissoftware/libCLImate.Ruby
|
10
10
|
#
|
@@ -40,7 +40,7 @@
|
|
40
40
|
module LibCLImate
|
41
41
|
|
42
42
|
# Current version of the libCLImate.Ruby library
|
43
|
-
VERSION = '0.
|
43
|
+
VERSION = '0.6.1'
|
44
44
|
|
45
45
|
private
|
46
46
|
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
data/test/unit/tc_abort.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
|
5
|
+
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
|
+
|
7
|
+
|
8
|
+
require 'libclimate'
|
9
|
+
|
10
|
+
require 'xqsr3/extensions/test/unit'
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
|
14
|
+
require 'stringio'
|
15
|
+
|
16
|
+
PROGRAM_VER_MAJOR = 3
|
17
|
+
|
18
|
+
class Test_Climate_infer_version_3_22 < Test::Unit::TestCase
|
19
|
+
|
20
|
+
PROGRAM_VER_MINOR = 22
|
21
|
+
|
22
|
+
def test_inference_of_version
|
23
|
+
|
24
|
+
strout = StringIO.new
|
25
|
+
|
26
|
+
climate = LibCLImate::Climate.new do |climate|
|
27
|
+
|
28
|
+
climate.program_name = 'myprog'
|
29
|
+
climate.stdout = strout
|
30
|
+
end.run [ 'myprog', '--version' ]
|
31
|
+
|
32
|
+
s = strout.string
|
33
|
+
|
34
|
+
assert_equal "myprog 3.22", s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Test_Climate_infer_version_3_2 < Test::Unit::TestCase
|
39
|
+
|
40
|
+
PROGRAM_VER_MINOR = 2
|
41
|
+
PROGRAM_VER_REVISION = 99
|
42
|
+
|
43
|
+
def test_inference_of_version
|
44
|
+
|
45
|
+
strout = StringIO.new
|
46
|
+
|
47
|
+
climate = LibCLImate::Climate.new do |climate|
|
48
|
+
|
49
|
+
climate.program_name = 'myprog'
|
50
|
+
climate.stdout = strout
|
51
|
+
end.run [ 'myprog', '--version' ]
|
52
|
+
|
53
|
+
s = strout.string
|
54
|
+
|
55
|
+
assert_equal "myprog 3.2.99", s
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# ############################## end of file ############################# #
|
60
|
+
|
61
|
+
|
data/test/unit/tc_minimal.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# test simple scenarios
|
4
4
|
|
@@ -234,6 +234,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
|
|
234
234
|
assert_not_nil r
|
235
235
|
assert_kind_of ::Hash, r
|
236
236
|
assert_equal 3, r.size
|
237
|
+
assert argv.equal? r.argv
|
237
238
|
assert_not_nil r[:flags]
|
238
239
|
assert_not_nil r[:options]
|
239
240
|
assert_not_nil r[:values]
|
@@ -291,6 +292,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
|
|
291
292
|
assert_not_nil r
|
292
293
|
assert_kind_of ::Hash, r
|
293
294
|
assert_equal 3, r.size
|
295
|
+
assert argv.equal? r.argv
|
294
296
|
assert_not_nil r[:flags]
|
295
297
|
assert_not_nil r[:options]
|
296
298
|
assert_not_nil r[:values]
|
@@ -335,6 +337,7 @@ class Test_Climate_minimal < Test::Unit::TestCase
|
|
335
337
|
assert_not_nil r
|
336
338
|
assert_kind_of ::Hash, r
|
337
339
|
assert_equal 3, r.size
|
340
|
+
assert argv.equal? r.argv
|
338
341
|
assert_not_nil r[:flags]
|
339
342
|
assert_not_nil r[:options]
|
340
343
|
assert_not_nil r[:values]
|
@@ -360,4 +363,3 @@ end
|
|
360
363
|
|
361
364
|
# ############################## end of file ############################# #
|
362
365
|
|
363
|
-
|
@@ -1,6 +1,6 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# test simple scenarios
|
3
|
+
# test simple scenarios (with CLASP)
|
4
4
|
|
5
5
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
6
|
|
@@ -360,4 +360,3 @@ end
|
|
360
360
|
|
361
361
|
# ############################## end of file ############################# #
|
362
362
|
|
363
|
-
|
@@ -1,6 +1,6 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# test
|
3
|
+
# test aliases
|
4
4
|
|
5
5
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
6
|
|
@@ -21,9 +21,9 @@ class Test_Climate_minimal < Test::Unit::TestCase
|
|
21
21
|
|
22
22
|
climate = LibCLImate::Climate.new do |climate|
|
23
23
|
|
24
|
-
climate.
|
25
|
-
climate.
|
26
|
-
climate.
|
24
|
+
climate.add_option('--action', alias: '-a') { |o, a| options[:action] = o.value }
|
25
|
+
climate.add_alias('--action=list', '-l')
|
26
|
+
climate.add_alias('--action=change', '-c')
|
27
27
|
end
|
28
28
|
|
29
29
|
# invoke via option
|
@@ -87,4 +87,3 @@ end
|
|
87
87
|
|
88
88
|
# ############################## end of file ############################# #
|
89
89
|
|
90
|
-
|
data/test/unit/tc_with_blocks.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# test
|
3
|
+
# test blocks
|
4
4
|
|
5
5
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
6
|
|
@@ -50,4 +50,3 @@ end
|
|
50
50
|
|
51
51
|
# ############################## end of file ############################# #
|
52
52
|
|
53
|
-
|
@@ -1,6 +1,6 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# test
|
3
|
+
# test blocks (with CLASP)
|
4
4
|
|
5
5
|
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
6
6
|
|
@@ -50,4 +50,3 @@ end
|
|
50
50
|
|
51
51
|
# ############################## end of file ############################# #
|
52
52
|
|
53
|
-
|
data/test/unit/ts_all.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libclimate-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Wilson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clasp-ruby
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/libclimate/version.rb
|
66
66
|
- test/scratch/blankzeroes.rb
|
67
67
|
- test/unit/tc_abort.rb
|
68
|
+
- test/unit/tc_infer_version.rb
|
68
69
|
- test/unit/tc_minimal.rb
|
69
70
|
- test/unit/tc_minimal_CLASP.rb
|
70
71
|
- test/unit/tc_test_aliases.rb
|