libclimate-ruby 0.14.0 → 0.15.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/README.md +50 -11
- data/examples/flag_and_option_specifications.from_DATA.md +4 -6
- data/examples/flag_and_option_specifications.from_DATA.rb +3 -3
- data/examples/flag_and_option_specifications.md +24 -8
- data/examples/flag_and_option_specifications.rb +12 -2
- data/examples/show_usage_and_version.md +4 -5
- data/examples/show_usage_and_version.rb +2 -2
- data/lib/libclimate/climate.rb +463 -188
- data/lib/libclimate/version.rb +3 -3
- data/test/unit/tc_minimal.rb +3 -3
- data/test/unit/tc_minimal_CLASP.rb +3 -3
- data/test/unit/tc_parse.rb +171 -0
- data/test/unit/tc_parse_and_verify.rb +157 -0
- data/test/unit/tc_values.rb +52 -0
- metadata +34 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a80c08e442469251d0436faea56241a72bb4b3c072d915a8d2ca3272430ee44
|
4
|
+
data.tar.gz: 80d05c56fd08159bababfb73e0c277e1cfa610f95fcffe75994199f0e9050918
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f88618dd50e250ccc2b15c9500ff97db1fe922394997a1ba9c4ceee38fa73f6830ea17432ea8666647a593befa0cdcfac0df95b78dcfbb85c15114bbcde384ec
|
7
|
+
data.tar.gz: ec7c28f7b08747f6e07f6e5c89e7707a8c3837f8b78b5e57693f72b55bc4dd36ee1ef26dcfc75c384b4bccd425927bdb46b568facf605a3db8cf3e02fed55b17
|
data/README.md
CHANGED
@@ -3,15 +3,6 @@ libCLImate, for Ruby
|
|
3
3
|
|
4
4
|
[](https://badge.fury.io/rb/libclimate-ruby)
|
5
5
|
|
6
|
-
## Introduction
|
7
|
-
|
8
|
-
**libCLImate** is a portable, lightweight mini-framework that encapsulates the common aspects of **C**ommand-**L**ine **I**nterface boilerplate, including:
|
9
|
-
|
10
|
-
- command-line argument parsing and sorting;
|
11
|
-
- provision of de-facto standard CLI facilities, such as responding to '--help' and '--version';
|
12
|
-
|
13
|
-
**libCLImate.Ruby** is the Ruby version.
|
14
|
-
|
15
6
|
## Table of Contents
|
16
7
|
|
17
8
|
1. [Introduction](#introduction)
|
@@ -20,6 +11,17 @@ libCLImate, for Ruby
|
|
20
11
|
4. [Examples](#examples)
|
21
12
|
5. [Project Information](#project-information)
|
22
13
|
|
14
|
+
## Introduction
|
15
|
+
|
16
|
+
**libCLImate** is a portable, lightweight mini-framework that encapsulates the common aspects of **C**ommand-**L**ine **I**nterface boilerplate, including:
|
17
|
+
|
18
|
+
- command-line argument parsing and sorting, into flags, options, and values;
|
19
|
+
- validating given and/or missing arguments;
|
20
|
+
- a declarative form of specifying the CLI elements for a program, including associating blocks with flag/option specifications;
|
21
|
+
- provision of de-facto standard CLI facilities, such as responding to '--help' and '--version';
|
22
|
+
|
23
|
+
**libCLImate.Ruby** is the Ruby version.
|
24
|
+
|
23
25
|
## Installation
|
24
26
|
|
25
27
|
Install via **gem** as in:
|
@@ -38,7 +40,41 @@ require 'libclimate'
|
|
38
40
|
|
39
41
|
## Components
|
40
42
|
|
41
|
-
|
43
|
+
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
|
+
|
45
|
+
```Ruby
|
46
|
+
options = {}
|
47
|
+
climate = LibCLImate::Climate.new do |cl|
|
48
|
+
|
49
|
+
cl.add_flag('--debug', alias: '-d', help: 'runs in Debug mode') do
|
50
|
+
|
51
|
+
options[:debug] = true
|
52
|
+
end
|
53
|
+
cl.add_option('--verbosity', alias: '-v', help: 'specifies the verbosity', values: [ 'terse', 'quiet', 'silent', 'chatty' ]) do |o, sp|
|
54
|
+
|
55
|
+
options[:verbosity] = o.value
|
56
|
+
end
|
57
|
+
cl.add_alias('--verbosity=chatty', '-c')
|
58
|
+
|
59
|
+
cl.version = [ 0, 1, 0 ]
|
60
|
+
|
61
|
+
cl.info_lines = [
|
62
|
+
|
63
|
+
'libCLImate.Ruby examples',
|
64
|
+
:version,
|
65
|
+
"Illustrates use of libCLImate.Ruby's specification of flags, options, and specifications",
|
66
|
+
'',
|
67
|
+
]
|
68
|
+
|
69
|
+
cl.constrain_values = 1..2
|
70
|
+
cl.usage_values = "<dir-1> [ <dir-2> ]"
|
71
|
+
cl.value_names = [
|
72
|
+
|
73
|
+
"first directory",
|
74
|
+
"second directory",
|
75
|
+
]
|
76
|
+
end
|
77
|
+
```
|
42
78
|
|
43
79
|
## Examples
|
44
80
|
|
@@ -68,10 +104,13 @@ Defect reports, feature requests, and pull requests are welcome on https://githu
|
|
68
104
|
* [**CLASP**](https://github.com/synesissoftware/CLASP/)
|
69
105
|
* [**CLASP.Go**](https://github.com/synesissoftware/CLASP.Go/)
|
70
106
|
* [**CLASP.js**](https://github.com/synesissoftware/CLASP.js/)
|
107
|
+
* [**CLASP.NET**](https://github.com/synesissoftware/CLASP.NET/)
|
108
|
+
* [**CLASP.Python**](https://github.com/synesissoftware/CLASP.Python/)
|
71
109
|
* [**CLASP.Ruby**](https://github.com/synesissoftware/CLASP.Ruby/)
|
72
|
-
* [**libCLImate** (C/C++)](https://github.com/synesissoftware/libCLImate
|
110
|
+
* [**libCLImate** (C/C++)](https://github.com/synesissoftware/libCLImate)
|
73
111
|
* [**xqsr3**](https://github.com/synesissoftware.com/libCLImate.Ruby-xml/)
|
74
112
|
|
75
113
|
### License
|
76
114
|
|
77
115
|
**libCLImate.Ruby** is released under the 3-clause BSD license. See [LICENSE](./LICENSE) for details.
|
116
|
+
|
@@ -27,7 +27,7 @@ climate = LibCLImate::Climate.load DATA do |cl|
|
|
27
27
|
cl.on_option('--verbosity') { |o, a| options[:verbosity] = o.value }
|
28
28
|
end
|
29
29
|
|
30
|
-
r = climate.
|
30
|
+
r = climate.parse_and_verify ARGV
|
31
31
|
|
32
32
|
|
33
33
|
# Program-specific processing of flags/options
|
@@ -87,10 +87,8 @@ libclimate:
|
|
87
87
|
-
|
88
88
|
version:
|
89
89
|
- 0
|
90
|
-
-
|
91
|
-
- "
|
92
|
-
```
|
93
|
-
```ruby
|
90
|
+
- 2
|
91
|
+
- "0"
|
94
92
|
```
|
95
93
|
|
96
94
|
## Usage
|
@@ -130,7 +128,7 @@ it gives the output:
|
|
130
128
|
|
131
129
|
```
|
132
130
|
libCLImate.Ruby examples
|
133
|
-
flag_and_option_specifications.from_DATA(.rb) 0.
|
131
|
+
flag_and_option_specifications.from_DATA(.rb) 0.2.0
|
134
132
|
Illustrates use of libCLImate.Ruby's specification of flags, options, and aliases, from DATA
|
135
133
|
|
136
134
|
USAGE: flag_and_option_specifications.from_DATA(.rb) [... flags/options ...] <dir-1> [ <dir-2> ]
|
@@ -18,7 +18,7 @@ climate = LibCLImate::Climate.load DATA do |cl|
|
|
18
18
|
cl.on_option('--verbosity') { |o, a| options[:verbosity] = o.value }
|
19
19
|
end
|
20
20
|
|
21
|
-
r = climate.
|
21
|
+
r = climate.parse_and_verify ARGV
|
22
22
|
|
23
23
|
|
24
24
|
# Program-specific processing of flags/options
|
@@ -78,6 +78,6 @@ libclimate:
|
|
78
78
|
-
|
79
79
|
version:
|
80
80
|
- 0
|
81
|
-
-
|
82
|
-
- "
|
81
|
+
- 2
|
82
|
+
- "0"
|
83
83
|
|
@@ -30,7 +30,7 @@ climate = LibCLImate::Climate.new do |cl|
|
|
30
30
|
end
|
31
31
|
cl.add_alias('--verbosity=chatty', '-c')
|
32
32
|
|
33
|
-
cl.version = [ 0,
|
33
|
+
cl.version = [ 0, 1, 0 ]
|
34
34
|
|
35
35
|
cl.info_lines = [
|
36
36
|
|
@@ -39,9 +39,17 @@ climate = LibCLImate::Climate.new do |cl|
|
|
39
39
|
"Illustrates use of libCLImate.Ruby's specification of flags, options, and specifications",
|
40
40
|
'',
|
41
41
|
]
|
42
|
+
|
43
|
+
cl.constrain_values = 1..2
|
44
|
+
cl.usage_values = "<dir-1> [ <dir-2> ]"
|
45
|
+
cl.value_names = [
|
46
|
+
|
47
|
+
"first directory",
|
48
|
+
"second directory",
|
49
|
+
]
|
42
50
|
end
|
43
51
|
|
44
|
-
r = climate.
|
52
|
+
r = climate.parse_and_verify ARGV
|
45
53
|
|
46
54
|
|
47
55
|
|
@@ -56,6 +64,10 @@ if options[:debug]
|
|
56
64
|
|
57
65
|
$stdout.puts 'Debug mode is specified'
|
58
66
|
end
|
67
|
+
|
68
|
+
# some notional output
|
69
|
+
|
70
|
+
$stdout.puts "processing in '#{r.values[0]}'" + (r.values.size > 1 ? " and '#{r.values[1]}'" : '')
|
59
71
|
```
|
60
72
|
|
61
73
|
## Usage
|
@@ -77,6 +89,7 @@ or (in a Unix shell):
|
|
77
89
|
it gives the output:
|
78
90
|
|
79
91
|
```
|
92
|
+
flag_and_option_specifications(.rb): first directory not specified; use --help for usage
|
80
93
|
```
|
81
94
|
|
82
95
|
### Show usage
|
@@ -91,7 +104,7 @@ it gives the output:
|
|
91
104
|
|
92
105
|
```
|
93
106
|
libCLImate.Ruby examples
|
94
|
-
flag_and_option_specifications.rb 0.0
|
107
|
+
flag_and_option_specifications.rb 0.1.0
|
95
108
|
Illustrates use of libCLImate.Ruby's specification of flags, options, and specifications
|
96
109
|
|
97
110
|
USAGE: flag_and_option_specifications.rb [ ... flags and options ... ]
|
@@ -124,7 +137,7 @@ flags/options:
|
|
124
137
|
If executed with the arguments
|
125
138
|
|
126
139
|
```
|
127
|
-
ruby examples/flag_and_option_specifications.rb --debug --verbosity=silent
|
140
|
+
ruby examples/flag_and_option_specifications.rb dir-1 dir-2 --debug --verbosity=silent
|
128
141
|
```
|
129
142
|
|
130
143
|
it gives the output:
|
@@ -132,6 +145,7 @@ it gives the output:
|
|
132
145
|
```
|
133
146
|
verbosity is specified as: silent
|
134
147
|
Debug mode is specified
|
148
|
+
processing in 'dir-1' and 'dir-2'
|
135
149
|
```
|
136
150
|
|
137
151
|
### Specify flags and options in short-form
|
@@ -139,7 +153,7 @@ Debug mode is specified
|
|
139
153
|
If executed with the arguments
|
140
154
|
|
141
155
|
```
|
142
|
-
ruby examples/flag_and_option_specifications.rb -v silent -d
|
156
|
+
ruby examples/flag_and_option_specifications.rb dir-1 dir-2 -v silent -d
|
143
157
|
```
|
144
158
|
|
145
159
|
it gives the (same) output:
|
@@ -147,6 +161,7 @@ it gives the (same) output:
|
|
147
161
|
```
|
148
162
|
verbosity is specified as: silent
|
149
163
|
Debug mode is specified
|
164
|
+
processing in 'dir-1' and 'dir-2'
|
150
165
|
```
|
151
166
|
|
152
167
|
### Specify flags and options in short-form, including an alias for an option-with-value
|
@@ -154,7 +169,7 @@ Debug mode is specified
|
|
154
169
|
If executed with the arguments
|
155
170
|
|
156
171
|
```
|
157
|
-
ruby examples/flag_and_option_specifications.rb -c -d
|
172
|
+
ruby examples/flag_and_option_specifications.rb -c -d dir-1 dir-2
|
158
173
|
```
|
159
174
|
|
160
175
|
it gives the output:
|
@@ -162,6 +177,7 @@ it gives the output:
|
|
162
177
|
```
|
163
178
|
verbosity is specified as: chatty
|
164
179
|
Debug mode is specified
|
180
|
+
processing in 'dir-1' and 'dir-2'
|
165
181
|
```
|
166
182
|
|
167
183
|
### Specify flags and options with combined short-form
|
@@ -169,7 +185,7 @@ Debug mode is specified
|
|
169
185
|
If executed with the arguments
|
170
186
|
|
171
187
|
```
|
172
|
-
ruby examples/flag_and_option_specifications.rb -dc
|
188
|
+
ruby examples/flag_and_option_specifications.rb -dc dir-1 dir-2
|
173
189
|
```
|
174
190
|
|
175
191
|
it gives the (same) output:
|
@@ -177,5 +193,5 @@ it gives the (same) output:
|
|
177
193
|
```
|
178
194
|
verbosity is specified as: chatty
|
179
195
|
Debug mode is specified
|
196
|
+
processing in 'dir-1' and 'dir-2'
|
180
197
|
```
|
181
|
-
|
@@ -21,7 +21,7 @@ climate = LibCLImate::Climate.new do |cl|
|
|
21
21
|
end
|
22
22
|
cl.add_alias('--verbosity=chatty', '-c')
|
23
23
|
|
24
|
-
cl.version = [ 0,
|
24
|
+
cl.version = [ 0, 1, 0 ]
|
25
25
|
|
26
26
|
cl.info_lines = [
|
27
27
|
|
@@ -30,9 +30,17 @@ climate = LibCLImate::Climate.new do |cl|
|
|
30
30
|
"Illustrates use of libCLImate.Ruby's specification of flags, options, and specifications",
|
31
31
|
'',
|
32
32
|
]
|
33
|
+
|
34
|
+
cl.constrain_values = 1..2
|
35
|
+
cl.usage_values = "<dir-1> [ <dir-2> ]"
|
36
|
+
cl.value_names = [
|
37
|
+
|
38
|
+
"first directory",
|
39
|
+
"second directory",
|
40
|
+
]
|
33
41
|
end
|
34
42
|
|
35
|
-
r = climate.
|
43
|
+
r = climate.parse_and_verify ARGV
|
36
44
|
|
37
45
|
|
38
46
|
|
@@ -49,5 +57,7 @@ if options[:debug]
|
|
49
57
|
end
|
50
58
|
|
51
59
|
|
60
|
+
# some notional output
|
52
61
|
|
62
|
+
$stdout.puts "processing in '#{r.values[0]}'" + (r.values.size > 1 ? " and '#{r.values[1]}'" : '')
|
53
63
|
|
@@ -19,7 +19,7 @@ require 'libclimate'
|
|
19
19
|
|
20
20
|
climate = LibCLImate::Climate.new do |cl|
|
21
21
|
|
22
|
-
cl.version = [ 0,
|
22
|
+
cl.version = [ 0, 1, 0 ]
|
23
23
|
|
24
24
|
cl.info_lines = [
|
25
25
|
|
@@ -30,7 +30,7 @@ climate = LibCLImate::Climate.new do |cl|
|
|
30
30
|
]
|
31
31
|
end
|
32
32
|
|
33
|
-
climate.
|
33
|
+
climate.parse_and_verify ARGV
|
34
34
|
|
35
35
|
|
36
36
|
|
@@ -71,7 +71,7 @@ it gives the output:
|
|
71
71
|
|
72
72
|
```
|
73
73
|
libCLImate.Ruby examples
|
74
|
-
show_usage_and_version.rb 0.0
|
74
|
+
show_usage_and_version.rb 0.1.0
|
75
75
|
Illustrates use of libCLImate.Ruby's automatic support for '--help' and '--version'
|
76
76
|
|
77
77
|
USAGE: show_usage_and_version.rb [ ... flags and options ... ]
|
@@ -96,7 +96,7 @@ If executed with the arguments
|
|
96
96
|
it gives the output:
|
97
97
|
|
98
98
|
```
|
99
|
-
show_usage_and_version.rb 0.0
|
99
|
+
show_usage_and_version.rb 0.1.0
|
100
100
|
```
|
101
101
|
|
102
102
|
### Unknown option
|
@@ -114,4 +114,3 @@ show_usage_and_version.rb: unrecognised flag/option: --unknown=value
|
|
114
114
|
```
|
115
115
|
|
116
116
|
with an exit code of 1
|
117
|
-
|
@@ -10,7 +10,7 @@ require 'libclimate'
|
|
10
10
|
|
11
11
|
climate = LibCLImate::Climate.new do |cl|
|
12
12
|
|
13
|
-
cl.version = [ 0,
|
13
|
+
cl.version = [ 0, 1, 0 ]
|
14
14
|
|
15
15
|
cl.info_lines = [
|
16
16
|
|
@@ -21,7 +21,7 @@ climate = LibCLImate::Climate.new do |cl|
|
|
21
21
|
]
|
22
22
|
end
|
23
23
|
|
24
|
-
climate.
|
24
|
+
climate.parse_and_verify ARGV
|
25
25
|
|
26
26
|
|
27
27
|
|