clasp-ruby 0.20.2 → 0.20.3
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.
- data/README.md +43 -21
- data/examples/cr-example.rb +2 -11
- data/examples/flag_and_option_specifications.md +15 -0
- data/lib/clasp/arguments.rb +1 -1
- data/lib/clasp/version.rb +1 -1
- data/test/unit/tc_default_value.rb +21 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,9 +1,27 @@
|
|
1
1
|
# CLASP.Ruby
|
2
|
-
Command-Line Argument Sorting and Parsing for Ruby
|
2
|
+
Command-Line Argument Sorting and Parsing, for Ruby
|
3
3
|
|
4
4
|
[](https://badge.fury.io/rb/clasp-ruby)
|
5
5
|
|
6
|
-
##
|
6
|
+
## Table of Contents
|
7
|
+
|
8
|
+
1. [Introduction](#introduction)
|
9
|
+
2. [Installation](#installation)
|
10
|
+
3. [Components](#components)
|
11
|
+
4. [Examples](#examples)
|
12
|
+
5. [Project Information](#project-information)
|
13
|
+
|
14
|
+
## Introduction
|
15
|
+
|
16
|
+
**CLASP** stands for Command-Line Argument Sorting and
|
17
|
+
Parsing. The first CLASP library was a C library with a C++ wrapper. There
|
18
|
+
have been several implementations in other languages. **CLASP.Ruby** is the
|
19
|
+
Ruby version.
|
20
|
+
|
21
|
+
All CLASP libraries provide the facilities to **C**ommand **L**ine
|
22
|
+
**I**nterface (**CLI**) programs as described in detail below.
|
23
|
+
|
24
|
+
## Installation
|
7
25
|
|
8
26
|
Install via **gem** as in:
|
9
27
|
|
@@ -19,19 +37,7 @@ Use via **require**, as in:
|
|
19
37
|
require 'clasp'
|
20
38
|
```
|
21
39
|
|
22
|
-
##
|
23
|
-
|
24
|
-
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).
|
25
|
-
|
26
|
-
## Description
|
27
|
-
|
28
|
-
**CLASP** stands for **C**ommand-**L**ine **A**rgument **S**orting and
|
29
|
-
**P**arsing. The first CLASP library was a C library with a C++ wrapper. There
|
30
|
-
have been several implementations in other languages. **CLASP.Ruby** is the
|
31
|
-
Ruby version.
|
32
|
-
|
33
|
-
All CLASP libraries provide the following facilities to **C**ommand **L**ine
|
34
|
-
**I**nterface (**CLI**) programs:
|
40
|
+
## Components
|
35
41
|
|
36
42
|
### Command-line parsing
|
37
43
|
|
@@ -101,7 +107,7 @@ Specifications = [
|
|
101
107
|
CLASP.Flag('--all', alias: '-a', help: 'processes all item types'),
|
102
108
|
CLASP.Flag('-c', help: 'count the processed items'),
|
103
109
|
CLASP.Option('--opt1', alias: '-o', help: 'an option of some kind', values_range: %w{ val1, val2 }),
|
104
|
-
CLASP.
|
110
|
+
CLASP.Flag('--opt1=val1', alias: '-v'),
|
105
111
|
|
106
112
|
# see next section for why these two are here
|
107
113
|
CLASP::Flag.Help,
|
@@ -195,15 +201,21 @@ then the program will output the following
|
|
195
201
|
cr-example.rb 0.1.2
|
196
202
|
```
|
197
203
|
|
198
|
-
##
|
204
|
+
## Examples
|
205
|
+
|
206
|
+
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).
|
207
|
+
|
208
|
+
## Project Information
|
209
|
+
|
210
|
+
### Where to get help
|
199
211
|
|
200
212
|
[GitHub Page](https://github.com/synesissoftware/CLASP.Ruby "GitHub Page")
|
201
213
|
|
202
|
-
|
214
|
+
### Contribution guidelines
|
203
215
|
|
204
216
|
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/CLASP.Ruby.
|
205
217
|
|
206
|
-
|
218
|
+
### Related projects
|
207
219
|
|
208
220
|
**CLASP.Ruby** is inspired by the [C/C++ CLASP library](https://github.com/synesissoftware/CLASP), which is documented in the articles:
|
209
221
|
|
@@ -211,9 +223,19 @@ Defect reports, feature requests, and pull requests are welcome on https://githu
|
|
211
223
|
* _[Anatomy of a CLI Program written in C](http://synesis.com.au/publishing/software-anatomies/anatomy-of-a-cli-program-written-in-c.html)_, Matthew Wilson, [CVu](http://accu.org/index.php/journals/c77/), September 2012; and
|
212
224
|
* _[Anatomy of a CLI Program written in C++](http://synesis.com.au/publishing/software-anatomies/anatomy-of-a-cli-program-written-in-c++.html)_, Matthew Wilson, [CVu](http://accu.org/index.php/journals/c77/), September 2015.
|
213
225
|
|
214
|
-
|
226
|
+
Other CLASP libraries include:
|
227
|
+
|
228
|
+
* [**CLASP**](https://github.com/synesissoftware/CLASP/)
|
229
|
+
* [**CLASP.Go**](https://github.com/synesissoftware/CLASP.Go/)
|
230
|
+
* [**CLASP.js**](https://github.com/synesissoftware/CLASP.js/)
|
231
|
+
* [**CLASP.NET**](https://github.com/synesissoftware/CLASP.NET/)
|
232
|
+
* [**CLASP.Python**](https://github.com/synesissoftware/CLASP.Python/)
|
233
|
+
|
234
|
+
Projects in which **CLASP.Ruby** is used include:
|
235
|
+
|
236
|
+
* [**libCLImate.Ruby**](https://github.com/synesissoftware/libCLImate.Ruby)
|
215
237
|
|
216
|
-
|
238
|
+
### License
|
217
239
|
|
218
240
|
**CLASP.Ruby** is released under the 3-clause BSD license. See LICENSE for details.
|
219
241
|
|
data/examples/cr-example.rb
CHANGED
@@ -1,16 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
|
-
|
4
|
-
# File: examples/cr-example.rb
|
3
|
+
# examples/cr-example.rb
|
5
4
|
#
|
6
|
-
# Purpose: COMPLETE_ME
|
7
|
-
#
|
8
|
-
# Created: 11 06 2016
|
9
|
-
# Updated: 11 06 2016
|
10
|
-
#
|
11
|
-
# Author: Matthew Wilson
|
12
|
-
#
|
13
|
-
#############################################################################
|
14
5
|
|
15
6
|
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
16
7
|
|
@@ -23,7 +14,7 @@ Specifications = [
|
|
23
14
|
CLASP.Flag('--all', alias: '-a', help: 'processes all item types'),
|
24
15
|
CLASP.Flag('-c', help: 'count the processed items'),
|
25
16
|
CLASP.Option('--opt1', alias: '-o', help: 'an option of some kind', values_range: %w{ val1, val2 }),
|
26
|
-
CLASP.
|
17
|
+
CLASP.Flag('--opt1=val1', alias: '-v'),
|
27
18
|
|
28
19
|
# see next section for why these two are here
|
29
20
|
CLASP::Flag.Help,
|
@@ -201,4 +201,19 @@ verbosity is specified as: chatty
|
|
201
201
|
Debug mode is specified
|
202
202
|
```
|
203
203
|
|
204
|
+
### Utilise the default value for verbosity
|
205
|
+
|
206
|
+
If executed with the arguments
|
207
|
+
|
208
|
+
```
|
209
|
+
ruby examples/flag_and_option_specifications.rb -d --verbosity=
|
210
|
+
```
|
211
|
+
|
212
|
+
it gives the output:
|
213
|
+
|
214
|
+
```
|
215
|
+
verbosity is specified as: terse
|
216
|
+
Debug mode is specified
|
217
|
+
```
|
218
|
+
|
204
219
|
|
data/lib/clasp/arguments.rb
CHANGED
data/lib/clasp/version.rb
CHANGED
@@ -28,7 +28,27 @@ class Test_DefaultValue < Test::Unit::TestCase
|
|
28
28
|
assert_nil option0.value
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def test_long_form_with_default_empty_value
|
32
|
+
|
33
|
+
specifications = [
|
34
|
+
|
35
|
+
CLASP.Option('--verbosity', values: [ 'silent', 'terse', 'normal', 'chatty', 'verbose' ], default_value: 'normal')
|
36
|
+
]
|
37
|
+
|
38
|
+
argv = [ '--verbosity=' ]
|
39
|
+
args = CLASP::Arguments.new(argv, specifications)
|
40
|
+
|
41
|
+
assert_equal 0, args.flags.size
|
42
|
+
assert_equal 1, args.options.size
|
43
|
+
assert_equal 0, args.values.size
|
44
|
+
|
45
|
+
option0 = args.options[0]
|
46
|
+
|
47
|
+
assert_equal '--verbosity', option0.name
|
48
|
+
assert_equal 'normal', option0.value
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_long_form_with_default_missing_value
|
32
52
|
|
33
53
|
specifications = [
|
34
54
|
|