libclimate-ruby 0.17.0 → 0.17.0.2
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/LICENSE +23 -21
- data/README.md +57 -30
- data/examples/flag_and_option_specifications.from_DATA.md +29 -29
- data/examples/flag_and_option_specifications.from_DATA.rb +4 -4
- data/examples/flag_and_option_specifications.md +45 -45
- data/examples/flag_and_option_specifications.rb +22 -22
- data/examples/show_usage_and_version.md +16 -16
- data/examples/show_usage_and_version.rb +7 -7
- data/lib/libclimate/climate.rb +1000 -1000
- data/lib/libclimate/version.rb +14 -14
- data/test/scratch/blankzeroes.rb +15 -15
- data/test/scratch/specifications.rb +23 -23
- data/test/unit/tc_abort.rb +43 -43
- data/test/unit/tc_double_slash_index.rb +74 -74
- data/test/unit/tc_infer_version.rb +48 -48
- data/test/unit/tc_minimal.rb +516 -516
- data/test/unit/tc_minimal_CLASP.rb +323 -323
- data/test/unit/tc_parse.rb +105 -105
- data/test/unit/tc_parse_and_verify.rb +94 -94
- data/test/unit/tc_test_specifications.rb +49 -49
- data/test/unit/tc_values.rb +294 -293
- data/test/unit/tc_with_blocks.rb +19 -19
- data/test/unit/tc_with_blocks_CLASP.rb +19 -19
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f7b6f4c5f156a946859492ec967c988d60b88d6b18ba7a65ec6cc96d2637577d
|
|
4
|
+
data.tar.gz: 025f947721e7a9a391621662ddcf41d9979b571e20f1fc93a6eb27ee670c16ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d5164021d09906286cd941cb4eab755b271b2bde0a3d147533c3d501ff64907f25207cbcb07c191f936a04911fab173f550baa96414c623d0e101cd17b40b2a
|
|
7
|
+
data.tar.gz: 829552df92abca1ab265bd93ceb1aec33a6e47bb05e717d6bc4530265a7210228222aa3514827f15b40a0959511d7cce8dfc0a75e8d04adb82e43db5097c5e14
|
data/LICENSE
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
libCLImate.Ruby
|
|
1
|
+
libCLImate.Ruby - BSD 3-Clause License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2016-2026, Matthew Wilson and Synesis Information Systems
|
|
4
|
+
Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
|
|
4
5
|
All rights reserved.
|
|
5
6
|
|
|
6
7
|
Redistribution and use in source and binary forms, with or without
|
|
7
8
|
modification, are permitted provided that the following conditions are met:
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
18
|
+
contributors may be used to endorse or promote products derived from
|
|
19
|
+
this software without specific prior written permission.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
24
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
25
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
26
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
27
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
28
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
29
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
30
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
31
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
20
32
|
|
|
21
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
22
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
23
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
# libCLImate.Ruby
|
|
1
|
+
# libCLImate.Ruby <!-- omit in toc -->
|
|
2
|
+
|
|
2
3
|
libCLImate, for Ruby
|
|
3
4
|
|
|
5
|
+

|
|
6
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
4
7
|
[](https://badge.fury.io/rb/libclimate-ruby)
|
|
8
|
+
[](https://rubygems.org/gems/libclimate-ruby)
|
|
9
|
+
[](https://github.com/synesissoftware/libCLImate.Ruby/releases/latest)
|
|
10
|
+
[](https://github.com/synesissoftware/libCLImate.Ruby/commits/master)
|
|
11
|
+
|
|
5
12
|
|
|
6
|
-
## Table of Contents
|
|
13
|
+
## Table of Contents <!-- omit in toc -->
|
|
14
|
+
|
|
15
|
+
- [Introduction](#introduction)
|
|
16
|
+
- [Installation](#installation)
|
|
17
|
+
- [Components](#components)
|
|
18
|
+
- [Examples](#examples)
|
|
19
|
+
- [Project Information](#project-information)
|
|
20
|
+
- [Where to get help](#where-to-get-help)
|
|
21
|
+
- [Contribution guidelines](#contribution-guidelines)
|
|
22
|
+
- [Dependencies](#dependencies)
|
|
23
|
+
- [Related projects](#related-projects)
|
|
24
|
+
- [License](#license)
|
|
7
25
|
|
|
8
|
-
1. [Introduction](#introduction)
|
|
9
|
-
2. [Installation](#installation)
|
|
10
|
-
3. [Components](#components)
|
|
11
|
-
4. [Examples](#examples)
|
|
12
|
-
5. [Project Information](#project-information)
|
|
13
26
|
|
|
14
27
|
## Introduction
|
|
15
28
|
|
|
@@ -22,12 +35,13 @@ libCLImate, for Ruby
|
|
|
22
35
|
|
|
23
36
|
**libCLImate.Ruby** is the Ruby version.
|
|
24
37
|
|
|
38
|
+
|
|
25
39
|
## Installation
|
|
26
40
|
|
|
27
41
|
Install via **gem** as in:
|
|
28
42
|
|
|
29
43
|
```
|
|
30
|
-
|
|
44
|
+
gem install libclimate-ruby
|
|
31
45
|
```
|
|
32
46
|
|
|
33
47
|
or add it to your `Gemfile`.
|
|
@@ -38,67 +52,76 @@ Use via **require**, as in:
|
|
|
38
52
|
require 'libclimate'
|
|
39
53
|
```
|
|
40
54
|
|
|
55
|
+
|
|
41
56
|
## Components
|
|
42
57
|
|
|
43
|
-
In common with several other variants of **libCLImate**, **libCLImate.Ruby** revolves around a ``Climate``
|
|
58
|
+
In common with several other variants of **libCLImate**, **libCLImate.Ruby** revolves around a ``Climate`` class whose initialiser takes a block and acts as a lightweight DSL for concise definition of a command-line parsing instance, as in:
|
|
44
59
|
|
|
45
60
|
```Ruby
|
|
46
61
|
options = {}
|
|
47
62
|
climate = LibCLImate::Climate.new do |cl|
|
|
48
63
|
|
|
49
|
-
|
|
64
|
+
cl.add_flag('--debug', alias: '-d', help: 'runs in Debug mode') do
|
|
50
65
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
options[:debug] = true
|
|
67
|
+
end
|
|
68
|
+
cl.add_option('--verbosity', alias: '-v', help: 'specifies the verbosity', values: [ 'terse', 'quiet', 'silent', 'chatty' ]) do |o, sp|
|
|
54
69
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
70
|
+
options[:verbosity] = o.value
|
|
71
|
+
end
|
|
72
|
+
cl.add_alias('--verbosity=chatty', '-c')
|
|
58
73
|
|
|
59
|
-
|
|
74
|
+
cl.version = [ 0, 1, 0 ]
|
|
60
75
|
|
|
61
|
-
|
|
76
|
+
cl.info_lines = [
|
|
62
77
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
'libCLImate.Ruby examples',
|
|
79
|
+
:version,
|
|
80
|
+
"Illustrates use of libCLImate.Ruby's specification of flags, options, and specifications",
|
|
81
|
+
'',
|
|
82
|
+
]
|
|
68
83
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
cl.constrain_values = 1..2
|
|
85
|
+
cl.usage_values = "<dir-1> [ <dir-2> ]"
|
|
86
|
+
cl.value_names = [
|
|
72
87
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
88
|
+
"first directory",
|
|
89
|
+
"second directory",
|
|
90
|
+
]
|
|
76
91
|
end
|
|
77
92
|
```
|
|
78
93
|
|
|
94
|
+
|
|
79
95
|
## Examples
|
|
80
96
|
|
|
81
97
|
Examples are provided in the ```examples``` directory, along with a markdown description for each. A detailed list TOC of them is provided in [EXAMPLES.md](./EXAMPLES.md).
|
|
82
98
|
|
|
83
99
|
It is instructive to see how much more succinct they are than those (offering precisely the same functionality) presented in [**CLASP.Ruby**](https://github.com/synesissoftware/CLASP.Ruby).
|
|
84
100
|
|
|
101
|
+
|
|
85
102
|
## Project Information
|
|
86
103
|
|
|
104
|
+
|
|
87
105
|
### Where to get help
|
|
88
106
|
|
|
89
107
|
[GitHub Page](https://github.com/synesissoftware/libCLImate.Ruby "GitHub Page")
|
|
90
108
|
|
|
109
|
+
|
|
91
110
|
### Contribution guidelines
|
|
92
111
|
|
|
93
112
|
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/libCLImate.Ruby.
|
|
94
113
|
|
|
114
|
+
|
|
95
115
|
### Dependencies
|
|
96
116
|
|
|
97
|
-
|
|
117
|
+
This library has efferent dependencies on:
|
|
98
118
|
|
|
99
119
|
* the [**CLASP.Ruby**](https://github.com/synesissoftware/CLASP.Ruby) library; and
|
|
100
120
|
* the [**xqsr3**](https://github.com/synesissoftware/xqsr3) library.
|
|
101
121
|
|
|
122
|
+
It has no known afferent dependencies.
|
|
123
|
+
|
|
124
|
+
|
|
102
125
|
### Related projects
|
|
103
126
|
|
|
104
127
|
* [**CLASP**](https://github.com/synesissoftware/CLASP/)
|
|
@@ -108,9 +131,13 @@ Defect reports, feature requests, and pull requests are welcome on https://githu
|
|
|
108
131
|
* [**CLASP.Python**](https://github.com/synesissoftware/CLASP.Python/)
|
|
109
132
|
* [**CLASP.Ruby**](https://github.com/synesissoftware/CLASP.Ruby/)
|
|
110
133
|
* [**libCLImate** (C/C++)](https://github.com/synesissoftware/libCLImate)
|
|
134
|
+
* [**libCLImate.Go** (Go)](https://github.com/synesissoftware/libCLImate.Go)
|
|
111
135
|
* [**xqsr3**](https://github.com/synesissoftware.com/libCLImate.Ruby-xml/)
|
|
112
136
|
|
|
137
|
+
|
|
113
138
|
### License
|
|
114
139
|
|
|
115
140
|
**libCLImate.Ruby** is released under the 3-clause BSD license. See [LICENSE](./LICENSE) for details.
|
|
116
141
|
|
|
142
|
+
|
|
143
|
+
<!-- ########################### end of file ########################### -->
|
|
@@ -22,9 +22,9 @@ require 'libclimate'
|
|
|
22
22
|
options = {}
|
|
23
23
|
climate = LibCLImate::Climate.load DATA do |cl|
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
cl.on_flag('--debug') { options[:debug] = true }
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
cl.on_option('--verbosity') { |o, a| options[:verbosity] = o.value }
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
r = climate.parse_and_verify ARGV
|
|
@@ -34,12 +34,12 @@ r = climate.parse_and_verify ARGV
|
|
|
34
34
|
|
|
35
35
|
if options[:verbosity]
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
$stdout.puts "verbosity is specified as: #{options[:verbosity]}"
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
if options[:debug]
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
$stdout.puts 'Debug mode is specified'
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
|
|
@@ -93,20 +93,20 @@ libclimate:
|
|
|
93
93
|
|
|
94
94
|
## Usage
|
|
95
95
|
|
|
96
|
-
NOTE: in order to demonstrate fully the utility of the *loading-from-source-file-YAML* facility, I've added a constraint for 1-2 values - notionally directories -
|
|
96
|
+
NOTE: in order to demonstrate fully the utility of the *loading-from-source-file-YAML* facility, I've added a constraint for 1-2 values - notionally directories -
|
|
97
97
|
|
|
98
98
|
### No arguments
|
|
99
99
|
|
|
100
100
|
If executed with no arguments
|
|
101
101
|
|
|
102
102
|
```
|
|
103
|
-
|
|
103
|
+
ruby examples/flag_and_option_specifications.from_DATA.rb
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
or (in a Unix shell):
|
|
107
107
|
|
|
108
108
|
```
|
|
109
|
-
|
|
109
|
+
./examples/flag_and_option_specifications.from_DATA.rb
|
|
110
110
|
```
|
|
111
111
|
|
|
112
112
|
it gives the output (with an exit code of **1**):
|
|
@@ -121,7 +121,7 @@ flag_and_option_specifications.from_DATA(.rb): first directory not specified; us
|
|
|
121
121
|
If executed with the arguments
|
|
122
122
|
|
|
123
123
|
```
|
|
124
|
-
|
|
124
|
+
ruby examples/flag_and_option_specifications.from_DATA.rb --help
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
it gives the output:
|
|
@@ -135,26 +135,26 @@ USAGE: flag_and_option_specifications.from_DATA(.rb) [... flags/options ...] <di
|
|
|
135
135
|
|
|
136
136
|
flags/options:
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
--help
|
|
139
|
+
shows this help and terminates
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
--version
|
|
142
|
+
shows version and terminates
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
-d
|
|
145
|
+
--debug
|
|
146
|
+
runs in Debug mode
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
148
|
+
--chatty --verbosity=chatty
|
|
149
|
+
-c --verbosity=chatty
|
|
150
|
+
--verbosity=<value>
|
|
151
|
+
specifies the verbosity
|
|
152
|
+
where <value> one of:
|
|
153
|
+
silent
|
|
154
|
+
quiet
|
|
155
|
+
terse
|
|
156
|
+
chatty
|
|
157
|
+
verbose
|
|
158
158
|
|
|
159
159
|
```
|
|
160
160
|
|
|
@@ -163,7 +163,7 @@ flags/options:
|
|
|
163
163
|
If executed with the arguments
|
|
164
164
|
|
|
165
165
|
```
|
|
166
|
-
|
|
166
|
+
ruby examples/flag_and_option_specifications.from_DATA.rb dir-1 dir-2 --debug --verbosity=silent
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
it gives the output:
|
|
@@ -179,7 +179,7 @@ processing in 'dir-1' and 'dir-2'
|
|
|
179
179
|
If executed with the arguments
|
|
180
180
|
|
|
181
181
|
```
|
|
182
|
-
|
|
182
|
+
ruby examples/flag_and_option_specifications.from_DATA.rb dir-1 dir-2 -v silent -d
|
|
183
183
|
```
|
|
184
184
|
|
|
185
185
|
it gives the (same) output:
|
|
@@ -195,7 +195,7 @@ processing in 'dir-1' and 'dir-2'
|
|
|
195
195
|
If executed with the arguments
|
|
196
196
|
|
|
197
197
|
```
|
|
198
|
-
|
|
198
|
+
ruby examples/flag_and_option_specifications.from_DATA.rb dir-1 dir-2 -c -d
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
it gives the output:
|
|
@@ -211,7 +211,7 @@ processing in 'dir-1' and 'dir-2'
|
|
|
211
211
|
If executed with the arguments
|
|
212
212
|
|
|
213
213
|
```
|
|
214
|
-
|
|
214
|
+
ruby examples/flag_and_option_specifications.from_DATA.rb dir-1 dir-2 -dc
|
|
215
215
|
```
|
|
216
216
|
|
|
217
217
|
it gives the (same) output:
|
|
@@ -13,9 +13,9 @@ require 'libclimate'
|
|
|
13
13
|
options = {}
|
|
14
14
|
climate = LibCLImate::Climate.load DATA do |cl|
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
cl.on_flag('--debug') { options[:debug] = true }
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
cl.on_option('--verbosity') { |o, a| options[:verbosity] = o.value }
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
r = climate.parse_and_verify ARGV
|
|
@@ -25,12 +25,12 @@ r = climate.parse_and_verify ARGV
|
|
|
25
25
|
|
|
26
26
|
if options[:verbosity]
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
$stdout.puts "verbosity is specified as: #{options[:verbosity]}"
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
if options[:debug]
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
$stdout.puts 'Debug mode is specified'
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
|
|
@@ -20,33 +20,33 @@ require 'libclimate'
|
|
|
20
20
|
options = {}
|
|
21
21
|
climate = LibCLImate::Climate.new do |cl|
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
cl.add_flag('--debug', alias: '-d', help: 'runs in Debug mode') do
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
options[:debug] = true
|
|
26
|
+
end
|
|
27
|
+
cl.add_option('--verbosity', alias: '-v', help: 'specifies the verbosity', values: [ 'terse', 'quiet', 'silent', 'chatty' ]) do |o, a|
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
options[:verbosity] = o.value
|
|
30
|
+
end
|
|
31
|
+
cl.add_alias('--verbosity=chatty', '-c')
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
cl.version = [ 0, 1, 0 ]
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
cl.info_lines = [
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
'libCLImate.Ruby examples',
|
|
38
|
+
:version,
|
|
39
|
+
"Illustrates use of libCLImate.Ruby's specification of flags, options, and specifications",
|
|
40
|
+
'',
|
|
41
|
+
]
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
cl.constrain_values = 1..2
|
|
44
|
+
cl.usage_values = "<dir-1> [ <dir-2> ]"
|
|
45
|
+
cl.value_names = [
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
"first directory",
|
|
48
|
+
"second directory",
|
|
49
|
+
]
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
r = climate.parse_and_verify ARGV
|
|
@@ -57,12 +57,12 @@ r = climate.parse_and_verify ARGV
|
|
|
57
57
|
|
|
58
58
|
if options[:verbosity]
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
$stdout.puts "verbosity is specified as: #{options[:verbosity]}"
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
if options[:debug]
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
$stdout.puts 'Debug mode is specified'
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
# some notional output
|
|
@@ -77,13 +77,13 @@ $stdout.puts "processing in '#{r.values[0]}'" + (r.values.size > 1 ? " and '#{r.
|
|
|
77
77
|
If executed with no arguments
|
|
78
78
|
|
|
79
79
|
```
|
|
80
|
-
|
|
80
|
+
ruby examples/flag_and_option_specifications.rb
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
or (in a Unix shell):
|
|
84
84
|
|
|
85
85
|
```
|
|
86
|
-
|
|
86
|
+
./examples/flag_and_option_specifications.rb
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
it gives the output:
|
|
@@ -97,7 +97,7 @@ flag_and_option_specifications(.rb): first directory not specified; use --help f
|
|
|
97
97
|
If executed with the arguments
|
|
98
98
|
|
|
99
99
|
```
|
|
100
|
-
|
|
100
|
+
ruby examples/flag_and_option_specifications.rb --help
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
it gives the output:
|
|
@@ -111,25 +111,25 @@ USAGE: flag_and_option_specifications.rb [ ... flags and options ... ]
|
|
|
111
111
|
|
|
112
112
|
flags/options:
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
-d
|
|
115
|
+
--debug
|
|
116
|
+
runs in Debug mode
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
-c --verbosity=chatty
|
|
119
|
+
-v <value>
|
|
120
|
+
--verbosity=<value>
|
|
121
|
+
specifies the verbosity
|
|
122
|
+
where <value> one of:
|
|
123
|
+
terse
|
|
124
|
+
quiet
|
|
125
|
+
silent
|
|
126
|
+
chatty
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
--help
|
|
129
|
+
Shows usage and terminates
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
--version
|
|
132
|
+
Shows version and terminates
|
|
133
133
|
```
|
|
134
134
|
|
|
135
135
|
### Specify flags and options in long-form
|
|
@@ -137,7 +137,7 @@ flags/options:
|
|
|
137
137
|
If executed with the arguments
|
|
138
138
|
|
|
139
139
|
```
|
|
140
|
-
|
|
140
|
+
ruby examples/flag_and_option_specifications.rb dir-1 dir-2 --debug --verbosity=silent
|
|
141
141
|
```
|
|
142
142
|
|
|
143
143
|
it gives the output:
|
|
@@ -153,7 +153,7 @@ processing in 'dir-1' and 'dir-2'
|
|
|
153
153
|
If executed with the arguments
|
|
154
154
|
|
|
155
155
|
```
|
|
156
|
-
|
|
156
|
+
ruby examples/flag_and_option_specifications.rb dir-1 dir-2 -v silent -d
|
|
157
157
|
```
|
|
158
158
|
|
|
159
159
|
it gives the (same) output:
|
|
@@ -169,7 +169,7 @@ processing in 'dir-1' and 'dir-2'
|
|
|
169
169
|
If executed with the arguments
|
|
170
170
|
|
|
171
171
|
```
|
|
172
|
-
|
|
172
|
+
ruby examples/flag_and_option_specifications.rb -c -d dir-1 dir-2
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
it gives the output:
|
|
@@ -185,7 +185,7 @@ processing in 'dir-1' and 'dir-2'
|
|
|
185
185
|
If executed with the arguments
|
|
186
186
|
|
|
187
187
|
```
|
|
188
|
-
|
|
188
|
+
ruby examples/flag_and_option_specifications.rb -dc dir-1 dir-2
|
|
189
189
|
```
|
|
190
190
|
|
|
191
191
|
it gives the (same) output:
|
|
@@ -11,33 +11,33 @@ require 'libclimate'
|
|
|
11
11
|
options = {}
|
|
12
12
|
climate = LibCLImate::Climate.new do |cl|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
cl.add_flag('--debug', alias: '-d', help: 'runs in Debug mode') do
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
options[:debug] = true
|
|
17
|
+
end
|
|
18
|
+
cl.add_option('--verbosity', alias: '-v', help: 'specifies the verbosity', values: [ 'terse', 'quiet', 'silent', 'chatty' ]) do |o, a|
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
options[:verbosity] = o.value
|
|
21
|
+
end
|
|
22
|
+
cl.add_alias('--verbosity=chatty', '-c')
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
cl.version = [ 0, 1, 0 ]
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
cl.info_lines = [
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
'libCLImate.Ruby examples',
|
|
29
|
+
:version,
|
|
30
|
+
"Illustrates use of libCLImate.Ruby's specification of flags, options, and specifications",
|
|
31
|
+
'',
|
|
32
|
+
]
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
cl.constrain_values = 1..2
|
|
35
|
+
cl.usage_values = "<dir-1> [ <dir-2> ]"
|
|
36
|
+
cl.value_names = [
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
"first directory",
|
|
39
|
+
"second directory",
|
|
40
|
+
]
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
r = climate.parse_and_verify ARGV
|
|
@@ -48,12 +48,12 @@ r = climate.parse_and_verify ARGV
|
|
|
48
48
|
|
|
49
49
|
if options[:verbosity]
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
$stdout.puts "verbosity is specified as: #{options[:verbosity]}"
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
if options[:debug]
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
$stdout.puts 'Debug mode is specified'
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
|