libclimate-ruby 0.7.5 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +53 -11
- data/lib/libclimate/climate.rb +210 -58
- data/lib/libclimate/version.rb +3 -3
- data/test/unit/tc_abort.rb +1 -0
- data/test/unit/tc_infer_version.rb +23 -0
- data/test/unit/tc_minimal_CLASP.rb +1 -0
- data/test/unit/tc_test_aliases.rb +1 -0
- data/test/unit/tc_values.rb +141 -0
- data/test/unit/tc_with_blocks.rb +1 -0
- data/test/unit/tc_with_blocks_CLASP.rb +1 -0
- metadata +17 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 353fcd858d3ab427e53c1a9413dd95b84a51ce60
|
4
|
+
data.tar.gz: 4e6800354074160420024c735c9c74c25479b61e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66435e1e61927c1c2cb3f8deeff70622ef6fe11d7829597fcdebf3e4310fde56c3d80d084cf29261f82f8914d344d97168e51a1de274f1c1a44560e44e411a10
|
7
|
+
data.tar.gz: 56b07a2b44395c8e0c72e7c6c553285a2f4de427a1cfc2268c49b7e8ac33ab9978de755f9c188eb0e4504f19d054b00db3ffd0c5b54c3fda40e33a99b958ce64
|
data/README.md
CHANGED
@@ -1,28 +1,70 @@
|
|
1
1
|
# libCLImate.Ruby
|
2
|
-
libCLImate for Ruby
|
2
|
+
libCLImate, for Ruby
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/libclimate-ruby.svg)](https://badge.fury.io/rb/libclimate-ruby)
|
5
5
|
|
6
|
-
##
|
6
|
+
## Introduction
|
7
7
|
|
8
|
-
|
8
|
+
**libCLImate** is a portable, lightweight mini-framework that encapsulates the common aspects of **C**ommand-**L**ine **I**nterface boilerplate, including:
|
9
9
|
|
10
|
-
|
10
|
+
- command-line argument parsing and sorting;
|
11
|
+
- provision of de-facto standard CLI facilities, such as responding to '--help' and '--version';
|
11
12
|
|
12
|
-
|
13
|
+
**libCLImate.Ruby** is the Ruby version.
|
13
14
|
|
14
|
-
##
|
15
|
+
## Table of Contents
|
16
|
+
|
17
|
+
1. [Introduction](#introduction)
|
18
|
+
2. [Installation](#installation)
|
19
|
+
3. [Components](#components)
|
20
|
+
4. [Project Information](#project-information)
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Install via **gem** as in:
|
25
|
+
|
26
|
+
```
|
27
|
+
gem install libclimate-ruby
|
28
|
+
```
|
29
|
+
|
30
|
+
or add it to your `Gemfile`.
|
31
|
+
|
32
|
+
Use via **require***, as in:
|
33
|
+
|
34
|
+
```Ruby
|
35
|
+
require 'libclimate-ruby'
|
36
|
+
```
|
37
|
+
|
38
|
+
## Components
|
39
|
+
|
40
|
+
T.B.C.
|
41
|
+
|
42
|
+
## Project Information
|
43
|
+
|
44
|
+
### Where to get help
|
15
45
|
|
16
46
|
[GitHub Page](https://github.com/synesissoftware/libCLImate.Ruby "GitHub Page")
|
17
47
|
|
18
|
-
|
48
|
+
### Contribution guidelines
|
19
49
|
|
20
50
|
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/libCLImate.Ruby.
|
21
51
|
|
22
|
-
|
52
|
+
### Dependencies
|
53
|
+
|
54
|
+
**libCLImate.Ruby** depends on:
|
55
|
+
|
56
|
+
* the [**CLASP.Ruby**](https://github.com/synesissoftware/CLASP.Ruby) library; and
|
57
|
+
* the [**xqsr3**](https://github.com/synesissoftware/xqsr3) library.
|
58
|
+
|
59
|
+
### Related projects
|
23
60
|
|
24
|
-
**libCLImate
|
61
|
+
* [**libCLImate C/C++](https://github.com/synesissoftware/libCLImate.Ruby)
|
62
|
+
* [**CLASP**](https://github.com/synesissoftware/CLASP/)
|
63
|
+
* [**CLASP.Go**](https://github.com/synesissoftware/CLASP.Go/)
|
64
|
+
* [**CLASP.js**](https://github.com/synesissoftware/CLASP.js/)
|
65
|
+
* [**CLASP.Ruby**](https://github.com/synesissoftware/CLASP.Ruby/)
|
66
|
+
* [xqsr3](https://github.com/synesissoftware.com/libCLImate.Ruby-xml/)
|
25
67
|
|
26
|
-
|
68
|
+
### License
|
27
69
|
|
28
|
-
**libCLImate.Ruby** is released under the 3-clause BSD license. See LICENSE for details.
|
70
|
+
**libCLImate.Ruby** is released under the 3-clause BSD license. See [LICENSE](./LICENSE) for details.
|
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: 12th March 2019
|
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-2019, 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
|
@@ -146,7 +146,7 @@ module LibCLImate
|
|
146
146
|
# program_options[:flavour] = check_flavour(o.value) or cl.abort "Invalid flavour '#{o.value}'; use --help for usage"
|
147
147
|
# end
|
148
148
|
#
|
149
|
-
# cl.
|
149
|
+
# cl.usage_values = '<value-1> [ ... <value-N> ]'
|
150
150
|
#
|
151
151
|
# cl.info_lines = [
|
152
152
|
#
|
@@ -169,6 +169,7 @@ class Climate
|
|
169
169
|
options.merge! stream: stdout, program_name: program_name, version: version, exit: exit_on_usage ? 0 : nil
|
170
170
|
options[:info_lines] = info_lines if info_lines
|
171
171
|
options[:values] = usage_values if usage_values
|
172
|
+
options[:flags_and_options] = flags_and_options if flags_and_options
|
172
173
|
|
173
174
|
CLASP.show_usage aliases, options
|
174
175
|
end
|
@@ -183,7 +184,7 @@ class Climate
|
|
183
184
|
# algorithm:
|
184
185
|
#
|
185
186
|
# 1. PROGRAM_VERSION: loaded from ctxt / global
|
186
|
-
# 2. PROGRAM_VER(SION)_(MAJOR|MINOR|REVISION|BUILD): loaded from
|
187
|
+
# 2. PROGRAM_VER(SION)_(MAJOR|MINOR|(PATCH|REVISION)|BUILD): loaded from
|
187
188
|
# ctxt / global
|
188
189
|
|
189
190
|
if ctxt
|
@@ -202,9 +203,15 @@ class Climate
|
|
202
203
|
|
203
204
|
ver << ctxt.const_get(:PROGRAM_VER_MINOR)
|
204
205
|
|
205
|
-
if ctxt.const_defined? :
|
206
|
+
if ctxt.const_defined?(:PROGRAM_VER_REVISION) || ctxt.const_defined?(:PROGRAM_VER_PATCH)
|
206
207
|
|
207
|
-
|
208
|
+
if ctxt.const_defined?(:PROGRAM_VER_PATCH)
|
209
|
+
|
210
|
+
ver << ctxt.const_get(:PROGRAM_VER_PATCH)
|
211
|
+
else
|
212
|
+
|
213
|
+
ver << ctxt.const_get(:PROGRAM_VER_REVISION)
|
214
|
+
end
|
208
215
|
|
209
216
|
if ctxt.const_defined? :PROGRAM_VER_BUILD
|
210
217
|
|
@@ -229,9 +236,15 @@ class Climate
|
|
229
236
|
|
230
237
|
ver << PROGRAM_VER_MINOR
|
231
238
|
|
232
|
-
if defined?
|
239
|
+
if defined?(PROGRAM_VER_REVISION) || defined?(PROGRAM_VER_PATCH)
|
240
|
+
|
241
|
+
if defined?(PROGRAM_VER_PATCH)
|
233
242
|
|
234
|
-
|
243
|
+
ver << PROGRAM_VER_PATCH
|
244
|
+
else
|
245
|
+
|
246
|
+
ver << PROGRAM_VER_REVISION
|
247
|
+
end
|
235
248
|
|
236
249
|
if defined? PROGRAM_VER_BUILD
|
237
250
|
|
@@ -258,12 +271,16 @@ class Climate
|
|
258
271
|
# - +options:+:: An options hash, containing any of the following options.
|
259
272
|
#
|
260
273
|
# * *Options*:
|
261
|
-
# - +:no_help_flag+:: Prevents the use of the
|
262
|
-
#
|
263
|
-
# - +:
|
274
|
+
# - +:no_help_flag+:: (boolean) Prevents the use of the
|
275
|
+
# +CLASP::Flag.Help+ flag-alias
|
276
|
+
# - +:no_version_flag+:: (boolean) Prevents the use of the
|
277
|
+
# +CLASP::Flag.Version+ flag-alias
|
278
|
+
# - +:program_name+:: (::String) An explicit program-name, which is
|
264
279
|
# inferred from +$0+ if this is +nil+
|
265
280
|
# - +:version+:: A version specification. If not specified, this is
|
266
281
|
# inferred
|
282
|
+
# - +:version_context+:: Object or class that defines a context for
|
283
|
+
# searching the version. Ignored if +:version+ is specified
|
267
284
|
#
|
268
285
|
# * *Block*:: An optional block which receives the constructing instance, allowing the user to modify the attributes.
|
269
286
|
def initialize(options={}) # :yields: climate
|
@@ -272,6 +289,8 @@ class Climate
|
|
272
289
|
|
273
290
|
options ||= {}
|
274
291
|
|
292
|
+
check_option options, :no_help_flag, type: :boolean, allow_nil: true
|
293
|
+
check_option options, :no_version_flag, type: :boolean, allow_nil: true
|
275
294
|
check_option options, :program_name, type: ::String, allow_nil: true
|
276
295
|
|
277
296
|
pr_name = options[:program_name]
|
@@ -279,10 +298,11 @@ class Climate
|
|
279
298
|
unless pr_name
|
280
299
|
|
281
300
|
pr_name = File.basename($0)
|
282
|
-
pr_name = (pr_name =~ /\.rb$/) ? "#$`(#$&)" : pr_name
|
301
|
+
pr_name = (pr_name =~ /\.(?:bat|cmd|rb|sh)$/) ? "#$`(#$&)" : pr_name
|
283
302
|
end
|
284
303
|
|
285
304
|
@aliases = []
|
305
|
+
@ignore_unknown = false
|
286
306
|
@exit_on_unknown = true
|
287
307
|
@exit_on_missing = true
|
288
308
|
@exit_on_usage = true
|
@@ -290,7 +310,10 @@ class Climate
|
|
290
310
|
set_program_name pr_name
|
291
311
|
@stdout = $stdout
|
292
312
|
@stderr = $stderr
|
313
|
+
@constrain_values = nil
|
314
|
+
@flags_and_options = flags_and_options
|
293
315
|
@usage_values = usage_values
|
316
|
+
@value_names = []
|
294
317
|
version_context = options[:version_context]
|
295
318
|
@version = options[:version] || infer_version_(version_context)
|
296
319
|
|
@@ -300,43 +323,66 @@ class Climate
|
|
300
323
|
yield self if block_given?
|
301
324
|
end
|
302
325
|
|
326
|
+
# [DEPRECATED] This method is now deprecated. Instead use
|
327
|
+
# +program_name=+
|
328
|
+
#
|
329
|
+
# @deprecated
|
303
330
|
def set_program_name name
|
304
331
|
|
305
|
-
if defined? Colcon
|
306
|
-
|
307
|
-
name = "#{::Colcon::Decorations::Bold}#{name}#{::Colcon::Decorations::Unbold}"
|
308
|
-
end
|
309
|
-
|
310
332
|
@program_name = name
|
311
333
|
end
|
312
334
|
|
313
335
|
# An array of aliases attached to the climate instance, whose contents should be modified by adding (or removing) CLASP aliases
|
314
|
-
# @return
|
336
|
+
# @return (::Array) The aliases
|
315
337
|
attr_reader :aliases
|
316
338
|
# Indicates whether exit will be called (with non-zero exit code) when a
|
317
339
|
# required command-line option is missing
|
318
|
-
# @return
|
340
|
+
# @return (boolean)
|
319
341
|
# @return *true* exit(1) will be called
|
320
342
|
# @return *false* exit will not be called
|
321
343
|
attr_accessor :exit_on_missing
|
344
|
+
# Indicates whether unknown flags or options will be ignored. This
|
345
|
+
# overrides +:exit_on_unknown+
|
346
|
+
attr_accessor :ignore_unknown
|
322
347
|
# Indicates whether exit will be called (with non-zero exit code) when an unknown command-line flag or option is encountered
|
323
|
-
# @return
|
348
|
+
# @return (boolean)
|
324
349
|
# @return *true* exit(1) will be called
|
325
350
|
# @return *false* exit will not be called
|
326
351
|
attr_accessor :exit_on_unknown
|
327
|
-
# @return
|
352
|
+
# @return (boolean) Indicates whether exit will be called (with zero exit code) when usage/version is requested on the command-line
|
328
353
|
attr_accessor :exit_on_usage
|
329
|
-
# @return
|
354
|
+
# @return (::Array) Optional array of string of program-information that will be written before the rest of the usage block when usage is requested on the command-line
|
330
355
|
attr_accessor :info_lines
|
331
|
-
# @return
|
332
|
-
|
333
|
-
|
356
|
+
# @return (::String) A program name; defaults to the name of the executing script
|
357
|
+
def program_name
|
358
|
+
|
359
|
+
name = @program_name
|
360
|
+
|
361
|
+
if defined?(Colcon) && @stdout.tty?
|
362
|
+
|
363
|
+
name = "#{::Colcon::Decorations::Bold}#{name}#{::Colcon::Decorations::Unbold}"
|
364
|
+
end
|
365
|
+
|
366
|
+
name
|
367
|
+
end
|
368
|
+
attr_writer :program_name
|
369
|
+
# @return (::IO) The output stream for normative output; defaults to $stdout
|
334
370
|
attr_accessor :stdout
|
335
|
-
# @return
|
371
|
+
# @return (::IO) The output stream for contingent output; defaults to $stderr
|
336
372
|
attr_accessor :stderr
|
337
|
-
# @return
|
373
|
+
# @return (::Integer, ::Range) Optional constraint on the values that
|
374
|
+
# must be provided to the program
|
375
|
+
attr_accessor :constrain_values
|
376
|
+
# @return (::String) Optional string to describe the flags and options
|
377
|
+
# section
|
378
|
+
attr_accessor :flags_and_options
|
379
|
+
# @return (::String) Optional string to describe the program values, eg \<xyz "[ { <<directory> | <file> } ]"
|
338
380
|
attr_accessor :usage_values
|
339
|
-
# @return
|
381
|
+
# @return (::Array) Zero-based array of names for values to be used when
|
382
|
+
# that value is not present (according to the +:constrain_values+
|
383
|
+
# attribute)
|
384
|
+
attr_accessor :value_names
|
385
|
+
# @return (::String, ::Array) A version string or an array of integers representing the version component(s)
|
340
386
|
attr_accessor :version
|
341
387
|
|
342
388
|
# Executes the prepared Climate instance
|
@@ -422,7 +468,12 @@ class Climate
|
|
422
468
|
|
423
469
|
message = "unrecognised flag '#{f}'; use --help for usage"
|
424
470
|
|
425
|
-
if
|
471
|
+
if false
|
472
|
+
|
473
|
+
elsif ignore_unknown
|
474
|
+
|
475
|
+
;
|
476
|
+
elsif exit_on_unknown
|
426
477
|
|
427
478
|
self.abort message
|
428
479
|
else
|
@@ -479,7 +530,12 @@ class Climate
|
|
479
530
|
|
480
531
|
message = "unrecognised option '#{o}'; use --help for usage"
|
481
532
|
|
482
|
-
if
|
533
|
+
if false
|
534
|
+
|
535
|
+
elsif ignore_unknown
|
536
|
+
|
537
|
+
;
|
538
|
+
elsif exit_on_unknown
|
483
539
|
|
484
540
|
self.abort message
|
485
541
|
else
|
@@ -497,40 +553,107 @@ class Climate
|
|
497
553
|
end
|
498
554
|
|
499
555
|
|
500
|
-
|
556
|
+
# now police any required options
|
557
|
+
|
558
|
+
required_aliases = aliases.select do |a|
|
559
|
+
|
560
|
+
a.kind_of?(::CLASP::Option) && a.required?
|
561
|
+
end
|
562
|
+
|
563
|
+
required_aliases = Hash[required_aliases.map { |a| [ a.name, a ] }]
|
564
|
+
|
565
|
+
given_options = Hash[results[:options][:given].map { |o| [ o.name, o ]}]
|
566
|
+
|
567
|
+
required_aliases.each do |k, a|
|
568
|
+
|
569
|
+
unless given_options.has_key? k
|
570
|
+
|
571
|
+
message = a.required_message
|
501
572
|
|
502
|
-
|
573
|
+
if exit_on_missing
|
503
574
|
|
504
|
-
|
575
|
+
self.abort message
|
576
|
+
else
|
577
|
+
|
578
|
+
if program_name && !program_name.empty?
|
579
|
+
|
580
|
+
message = "#{program_name}: #{message}"
|
581
|
+
end
|
582
|
+
|
583
|
+
stderr.puts message
|
584
|
+
end
|
585
|
+
|
586
|
+
results[:missing_option_aliases] << a
|
505
587
|
end
|
588
|
+
end
|
506
589
|
|
507
|
-
|
590
|
+
# now police the values
|
508
591
|
|
509
|
-
|
592
|
+
values_constraint = constrain_values
|
593
|
+
values_constraint = values_constraint.begin if ::Range === values_constraint && values_constraint.end == values_constraint.begin
|
594
|
+
val_names = ::Array === value_names ? value_names : []
|
510
595
|
|
511
|
-
|
596
|
+
case values_constraint
|
597
|
+
when nil
|
512
598
|
|
513
|
-
|
599
|
+
;
|
600
|
+
when ::Integer
|
514
601
|
|
515
|
-
|
602
|
+
unless values.size == values_constraint
|
516
603
|
|
517
|
-
|
604
|
+
if name = val_names[values.size]
|
518
605
|
|
519
|
-
|
520
|
-
|
606
|
+
message = name + ' not specified; use --help for usage'
|
607
|
+
else
|
521
608
|
|
522
|
-
|
609
|
+
message = "wrong number of values: #{values.size} given, #{values_constraint} required; use --help for usage"
|
610
|
+
end
|
523
611
|
|
524
|
-
|
525
|
-
end
|
612
|
+
if exit_on_unknown
|
526
613
|
|
527
|
-
|
614
|
+
self.abort message
|
615
|
+
else
|
616
|
+
|
617
|
+
if program_name && !program_name.empty?
|
618
|
+
|
619
|
+
message = "#{program_name}: #{message}"
|
528
620
|
end
|
529
621
|
|
530
|
-
|
622
|
+
stderr.puts message
|
623
|
+
end
|
624
|
+
end
|
625
|
+
when ::Range
|
626
|
+
|
627
|
+
unless values_constraint.include? values.size
|
628
|
+
|
629
|
+
if name = val_names[values.size]
|
630
|
+
|
631
|
+
message = name + ' not specified; use --help for usage'
|
632
|
+
else
|
633
|
+
|
634
|
+
message = "wrong number of values: #{values.size} givens, #{values_constraint.begin} - #{values_constraint.end - (values_constraint.exclude_end? ? 1 : 0)} required; use --help for usage"
|
635
|
+
end
|
636
|
+
|
637
|
+
if exit_on_unknown
|
638
|
+
|
639
|
+
self.abort message
|
640
|
+
else
|
641
|
+
|
642
|
+
if program_name && !program_name.empty?
|
643
|
+
|
644
|
+
message = "#{program_name}: #{message}"
|
645
|
+
end
|
646
|
+
|
647
|
+
stderr.puts message
|
531
648
|
end
|
649
|
+
end
|
650
|
+
else
|
651
|
+
|
652
|
+
warn "value of 'constrain_values' attribute - '#{constrain_values}' (#{constrain_values.class}) - of wrong type : must be #{::Integer}, #{::Range}, or nil"
|
532
653
|
end
|
533
654
|
|
655
|
+
|
656
|
+
|
534
657
|
def results.flags
|
535
658
|
|
536
659
|
self[:flags]
|
@@ -602,7 +725,7 @@ class Climate
|
|
602
725
|
# === Signature
|
603
726
|
#
|
604
727
|
# * *Parameters*
|
605
|
-
# - +
|
728
|
+
# - +name_or_flag+:: The flag name or instance of CLASP::Flag
|
606
729
|
# - +options+:: An options hash, containing any of the following options.
|
607
730
|
#
|
608
731
|
# * *Options*
|
@@ -610,13 +733,26 @@ class Climate
|
|
610
733
|
# - +:alias+::
|
611
734
|
# - +:aliases+::
|
612
735
|
# - +:extras+::
|
613
|
-
def add_flag(
|
736
|
+
def add_flag(name_or_flag, options={}, &block)
|
737
|
+
|
738
|
+
check_parameter name_or_flag, 'name_or_flag', allow_nil: false, types: [ ::String, ::Symbol, ::CLASP::Flag ]
|
614
739
|
|
615
|
-
|
740
|
+
if ::CLASP::Flag === name_or_flag
|
616
741
|
|
617
|
-
|
742
|
+
aliases << name_or_flag
|
743
|
+
else
|
744
|
+
|
745
|
+
aliases << CLASP.Flag(name_or_flag, **options, &block)
|
746
|
+
end
|
618
747
|
end
|
619
748
|
|
749
|
+
# Adds an option to +aliases+
|
750
|
+
#
|
751
|
+
# === Signature
|
752
|
+
#
|
753
|
+
# * *Parameters*
|
754
|
+
# - +name_or_option+:: The option name or instance of CLASP::Option
|
755
|
+
# - +options+:: An options hash, containing any of the following options.
|
620
756
|
#
|
621
757
|
# * *Options*
|
622
758
|
# - +:alias+::
|
@@ -625,19 +761,25 @@ class Climate
|
|
625
761
|
# - +:values_range+::
|
626
762
|
# - +:default_value+::
|
627
763
|
# - +:extras+::
|
628
|
-
def add_option(
|
764
|
+
def add_option(name_or_option, options={}, &block)
|
765
|
+
|
766
|
+
check_parameter name_or_option, 'name_or_option', allow_nil: false, types: [ ::String, ::Symbol, ::CLASP::Option ]
|
629
767
|
|
630
|
-
|
768
|
+
if ::CLASP::Option === name_or_option
|
631
769
|
|
632
|
-
|
770
|
+
aliases << name_or_option
|
771
|
+
else
|
772
|
+
|
773
|
+
aliases << CLASP.Option(name_or_option, **options, &block)
|
774
|
+
end
|
633
775
|
end
|
634
776
|
|
635
|
-
# Adds
|
777
|
+
# Adds an alias to +aliases+
|
636
778
|
#
|
637
779
|
# === Signature
|
638
780
|
#
|
639
781
|
# * *Parameters*
|
640
|
-
# - +
|
782
|
+
# - +name_or_alias+:: The flag/option name or the valued option
|
641
783
|
# - +aliases+:: One or more aliases
|
642
784
|
#
|
643
785
|
# === Examples
|
@@ -670,12 +812,22 @@ class Climate
|
|
670
812
|
# +climate.add_option('--verbosity')+
|
671
813
|
# +climate.add_alias('--verbosity=succinct', '-s')+
|
672
814
|
# +climate.add_alias('--verbosity=verbose', '-v')+
|
673
|
-
def add_alias(
|
815
|
+
def add_alias(name_or_alias, *aliases)
|
674
816
|
|
675
|
-
check_parameter
|
817
|
+
check_parameter name_or_alias, 'name_or_alias', allow_nil: false, types: [ ::String, ::Symbol, ::CLASP::Flag, ::CLASP::Option ]
|
676
818
|
raise ArgumentError, "must supply at least one alias" if aliases.empty?
|
677
819
|
|
678
|
-
|
820
|
+
case name_or_alias
|
821
|
+
when ::CLASP::Flag
|
822
|
+
|
823
|
+
self.aliases << name_or_alias
|
824
|
+
when ::CLASP::Option
|
825
|
+
|
826
|
+
self.aliases << name_or_alias
|
827
|
+
else
|
828
|
+
|
829
|
+
self.aliases << CLASP.Alias(name_or_alias, aliases: aliases)
|
830
|
+
end
|
679
831
|
end
|
680
832
|
end # class Climate
|
681
833
|
|
data/lib/libclimate/version.rb
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
# Purpose: Version for libclimate.Ruby library
|
5
5
|
#
|
6
6
|
# Created: 13th July 2015
|
7
|
-
# Updated:
|
7
|
+
# Updated: 12th March 2019
|
8
8
|
#
|
9
9
|
# Home: http://github.com/synesissoftware/libCLImate.Ruby
|
10
10
|
#
|
11
|
-
# Copyright (c) 2015-
|
11
|
+
# Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
12
12
|
# All rights reserved.
|
13
13
|
#
|
14
14
|
# Redistribution and use in source and binary forms, with or without
|
@@ -43,7 +43,7 @@
|
|
43
43
|
module LibCLImate
|
44
44
|
|
45
45
|
# Current version of the libCLImate.Ruby library
|
46
|
-
VERSION = '0.
|
46
|
+
VERSION = '0.11.0'
|
47
47
|
|
48
48
|
private
|
49
49
|
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
data/test/unit/tc_abort.rb
CHANGED
@@ -82,6 +82,29 @@ class Test_Climate_infer_PROGRAM_VERSION_as_array < Test::Unit::TestCase
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
class Test_Climate_infer_version_3_2_99_via_PATCH < Test::Unit::TestCase
|
86
|
+
|
87
|
+
PROGRAM_VER_MINOR = 7
|
88
|
+
PROGRAM_VER_PATCH = 101
|
89
|
+
|
90
|
+
def test_inference_of_version
|
91
|
+
|
92
|
+
strout = StringIO.new
|
93
|
+
|
94
|
+
climate = LibCLImate::Climate.new(version_context: self) do |cl|
|
95
|
+
|
96
|
+
cl.program_name = 'myprog'
|
97
|
+
cl.stdout = strout
|
98
|
+
|
99
|
+
cl.exit_on_usage = false
|
100
|
+
end.run [ 'myprog', '--version' ]
|
101
|
+
|
102
|
+
s = strout.string
|
103
|
+
|
104
|
+
assert_equal "myprog 3.7.101", s.chomp
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
85
108
|
# ############################## end of file ############################# #
|
86
109
|
|
87
110
|
|
@@ -0,0 +1,141 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
4
|
+
|
5
|
+
|
6
|
+
require 'libclimate'
|
7
|
+
|
8
|
+
require 'xqsr3/extensions/test/unit'
|
9
|
+
require 'test/unit'
|
10
|
+
|
11
|
+
require 'stringio'
|
12
|
+
|
13
|
+
class Test_Climate_values_constraints < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def test_constrain_with_no_constraint
|
16
|
+
|
17
|
+
stdout = StringIO.new
|
18
|
+
stderr = StringIO.new
|
19
|
+
|
20
|
+
climate = LibCLImate::Climate.new do |cl|
|
21
|
+
|
22
|
+
cl.exit_on_unknown = false
|
23
|
+
|
24
|
+
cl.stdout = stdout
|
25
|
+
cl.stderr = stderr
|
26
|
+
end
|
27
|
+
|
28
|
+
stdout.truncate(0)
|
29
|
+
stderr.truncate(0)
|
30
|
+
r = climate.run [ ]
|
31
|
+
assert_equal 0, r.values.size
|
32
|
+
assert_empty stdout.string
|
33
|
+
assert_empty stderr.string
|
34
|
+
|
35
|
+
stdout.truncate(0)
|
36
|
+
stderr.truncate(0)
|
37
|
+
r = climate.run [ 'value-1' ]
|
38
|
+
assert_equal 1, r.values.size
|
39
|
+
assert_empty stdout.string
|
40
|
+
assert_empty stderr.string
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_constrain_with_integer
|
44
|
+
|
45
|
+
stdout = StringIO.new
|
46
|
+
stderr = StringIO.new
|
47
|
+
|
48
|
+
climate = LibCLImate::Climate.new do |cl|
|
49
|
+
|
50
|
+
cl.exit_on_unknown = false
|
51
|
+
|
52
|
+
cl.stdout = stdout
|
53
|
+
cl.stderr = stderr
|
54
|
+
|
55
|
+
cl.constrain_values = 2
|
56
|
+
end
|
57
|
+
|
58
|
+
stdout.truncate(0)
|
59
|
+
stderr.truncate(0)
|
60
|
+
r = climate.run [ ]
|
61
|
+
assert_equal 0, r.values.size
|
62
|
+
assert_empty stdout.string
|
63
|
+
assert_not_empty stderr.string
|
64
|
+
assert_match /wrong number of values.*0 given.*2 required.*/, stderr.string
|
65
|
+
|
66
|
+
stdout.truncate(0)
|
67
|
+
stderr.truncate(0)
|
68
|
+
r = climate.run [ 'value-1' ]
|
69
|
+
assert_equal 1, r.values.size
|
70
|
+
assert_empty stdout.string
|
71
|
+
assert_not_empty stderr.string
|
72
|
+
assert_match /wrong number of values.*1 given.*2 required.*/, stderr.string
|
73
|
+
|
74
|
+
stdout.truncate(0)
|
75
|
+
stderr.truncate(0)
|
76
|
+
r = climate.run [ 'value-1', 'value-2' ]
|
77
|
+
assert_equal 2, r.values.size
|
78
|
+
assert_empty stdout.string
|
79
|
+
assert_empty stderr.string
|
80
|
+
|
81
|
+
stdout.truncate(0)
|
82
|
+
stderr.truncate(0)
|
83
|
+
r = climate.run [ 'value-1', 'value-2', 'value-3' ]
|
84
|
+
assert_equal 3, r.values.size
|
85
|
+
assert_empty stdout.string
|
86
|
+
assert_not_empty stderr.string
|
87
|
+
assert_match /wrong number of values.*3 given.*2 required.*/, stderr.string
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_constrain_with_simple_range
|
91
|
+
|
92
|
+
stdout = StringIO.new
|
93
|
+
stderr = StringIO.new
|
94
|
+
|
95
|
+
climate = LibCLImate::Climate.new do |cl|
|
96
|
+
|
97
|
+
cl.exit_on_unknown = false
|
98
|
+
|
99
|
+
cl.stdout = stdout
|
100
|
+
cl.stderr = stderr
|
101
|
+
|
102
|
+
cl.constrain_values = 0..2
|
103
|
+
end
|
104
|
+
|
105
|
+
stdout.truncate(0)
|
106
|
+
stderr.truncate(0)
|
107
|
+
r = climate.run [ ]
|
108
|
+
assert_equal 0, r.values.size
|
109
|
+
assert_empty stdout.string
|
110
|
+
assert_empty stderr.string
|
111
|
+
|
112
|
+
stdout.truncate(0)
|
113
|
+
stderr.truncate(0)
|
114
|
+
r = climate.run [ 'value-1' ]
|
115
|
+
assert_equal 1, r.values.size
|
116
|
+
assert_empty stdout.string
|
117
|
+
assert_empty stderr.string
|
118
|
+
|
119
|
+
stdout.truncate(0)
|
120
|
+
stderr.truncate(0)
|
121
|
+
r = climate.run [ 'value-1', 'value-2' ]
|
122
|
+
assert_equal 2, r.values.size
|
123
|
+
assert_empty stdout.string
|
124
|
+
assert_empty stderr.string
|
125
|
+
|
126
|
+
stdout.truncate(0)
|
127
|
+
stderr.truncate(0)
|
128
|
+
r = climate.run [ 'value-1', 'value-2', 'value-3' ]
|
129
|
+
assert_equal 3, r.values.size
|
130
|
+
assert_empty stdout.string
|
131
|
+
assert_not_empty stderr.string
|
132
|
+
|
133
|
+
stdout.truncate(0)
|
134
|
+
stderr.truncate(0)
|
135
|
+
r = climate.run [ 'value-1', 'value-2', 'value-3', 'value-4' ]
|
136
|
+
assert_equal 4, r.values.size
|
137
|
+
assert_empty stdout.string
|
138
|
+
assert_not_empty stderr.string
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
data/test/unit/tc_with_blocks.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libclimate-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.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:
|
11
|
+
date: 2019-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clasp-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
20
|
-
- - <
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '1.0'
|
19
|
+
version: '0.15'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.13.2
|
30
|
-
- - <
|
24
|
+
- - ~>
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
26
|
+
version: '0.15'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: xqsr3
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- -
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 0.8.4
|
40
|
-
- - <
|
31
|
+
- - ~>
|
41
32
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
33
|
+
version: '0.31'
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
|
-
- -
|
38
|
+
- - ~>
|
48
39
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.
|
50
|
-
- - <
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '1.0'
|
40
|
+
version: '0.31'
|
53
41
|
description: |2+
|
54
42
|
|
55
43
|
email: matthew@synesis.com.au
|
@@ -57,12 +45,10 @@ executables: []
|
|
57
45
|
extensions: []
|
58
46
|
extra_rdoc_files: []
|
59
47
|
files:
|
60
|
-
- LICENSE
|
61
|
-
- README.md
|
62
|
-
- lib/libclimate.rb
|
63
48
|
- lib/libclimate/climate.rb
|
64
49
|
- lib/libclimate/libclimate.rb
|
65
50
|
- lib/libclimate/version.rb
|
51
|
+
- lib/libclimate.rb
|
66
52
|
- test/scratch/aliases.rb
|
67
53
|
- test/scratch/blankzeroes.rb
|
68
54
|
- test/unit/tc_abort.rb
|
@@ -70,9 +56,12 @@ files:
|
|
70
56
|
- test/unit/tc_minimal.rb
|
71
57
|
- test/unit/tc_minimal_CLASP.rb
|
72
58
|
- test/unit/tc_test_aliases.rb
|
59
|
+
- test/unit/tc_values.rb
|
73
60
|
- test/unit/tc_with_blocks.rb
|
74
61
|
- test/unit/tc_with_blocks_CLASP.rb
|
75
62
|
- test/unit/ts_all.rb
|
63
|
+
- README.md
|
64
|
+
- LICENSE
|
76
65
|
homepage: http://www.libclimate.org/
|
77
66
|
licenses:
|
78
67
|
- Modified BSD
|
@@ -83,9 +72,9 @@ require_paths:
|
|
83
72
|
- lib
|
84
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
74
|
requirements:
|
86
|
-
- -
|
75
|
+
- - ~>
|
87
76
|
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
77
|
+
version: '2.0'
|
89
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
79
|
requirements:
|
91
80
|
- - '>='
|
@@ -93,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
82
|
version: '0'
|
94
83
|
requirements: []
|
95
84
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.0.14.1
|
97
86
|
signing_key:
|
98
87
|
specification_version: 4
|
99
88
|
summary: libCLImate.Ruby
|