clasp-ruby 0.23.0.1 → 0.23.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +63 -52
- data/examples/cr-example.rb +16 -16
- data/examples/flag_and_option_specifications.md +25 -25
- data/examples/flag_and_option_specifications.rb +6 -6
- data/examples/show_usage_and_version.md +5 -5
- data/examples/show_usage_and_version.rb +1 -1
- data/examples/simple_command_line_no_specifications.rb +1 -1
- data/lib/clasp/arguments.rb +538 -537
- data/lib/clasp/clasp.rb +7 -7
- data/lib/clasp/cli.rb +140 -135
- data/lib/clasp/doc_.rb +3 -3
- data/lib/clasp/old_module.rb +3 -3
- data/lib/clasp/specifications.rb +337 -333
- data/lib/clasp/util/exceptions.rb +17 -17
- data/lib/clasp/util/value_parser.rb +97 -97
- data/lib/clasp/version.rb +15 -15
- data/lib/clasp-ruby.rb +3 -2
- data/lib/clasp.rb +3 -2
- data/test/scratch/test_list_command_line.rb +6 -6
- data/test/scratch/test_specifications.rb +14 -14
- data/test/scratch/test_usage.rb +6 -6
- data/test/scratch/test_usage_from_DATA.rb +1 -1
- data/test/scratch/test_usage_with_duplicate_specifications.rb +6 -6
- data/test/unit/tc_ARGV_rewrite.rb +36 -38
- data/test/unit/tc_arguments_1.rb +694 -694
- data/test/unit/tc_arguments_2.rb +52 -53
- data/test/unit/tc_arguments_3.rb +77 -77
- data/test/unit/tc_arguments_inspect.rb +55 -56
- data/test/unit/tc_cli.rb +4 -4
- data/test/unit/tc_default_value.rb +91 -91
- data/test/unit/tc_defaults_1.rb +38 -38
- data/test/unit/tc_examples_Arguments.rb +130 -132
- data/test/unit/tc_extras.rb +24 -26
- data/test/unit/tc_option_required.rb +38 -39
- data/test/unit/tc_option_value_aliases.rb +44 -44
- data/test/unit/tc_specifications.rb +7 -8
- data/test/unit/tc_typed_options.rb +204 -204
- data/test/unit/tc_usage.rb +112 -55
- data/test/unit/tc_with_action.rb +23 -24
- data/test/unit/ts_all.rb +1 -1
- metadata +5 -4
data/test/unit/tc_usage.rb
CHANGED
@@ -10,101 +10,158 @@ require 'stringio'
|
|
10
10
|
|
11
11
|
class Test_Usage < Test::Unit::TestCase
|
12
12
|
|
13
|
-
|
13
|
+
def test_empty_default
|
14
14
|
|
15
|
-
|
15
|
+
specifications = []
|
16
16
|
|
17
|
-
|
17
|
+
stream = StringIO.new
|
18
18
|
|
19
|
-
|
19
|
+
CLASP.show_usage specifications, stream: stream, program_name: 'myprog'
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
expected = <<EOF_output
|
22
|
+
USAGE: myprog [ ... flags and options ... ]
|
23
23
|
|
24
|
-
|
24
|
+
EOF_output
|
25
|
+
actual = stream.string
|
25
26
|
|
26
|
-
|
27
|
+
assert_equal expected, actual
|
28
|
+
end
|
27
29
|
|
28
|
-
|
30
|
+
def test_empty_all
|
29
31
|
|
30
|
-
|
32
|
+
specifications = []
|
31
33
|
|
32
|
-
|
33
|
-
end
|
34
|
+
stream = StringIO.new
|
34
35
|
|
35
|
-
|
36
|
+
CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: ''
|
36
37
|
|
37
|
-
|
38
|
+
expected = <<EOF_output
|
39
|
+
USAGE: myprog
|
38
40
|
|
39
|
-
|
41
|
+
EOF_output
|
42
|
+
actual = stream.string
|
40
43
|
|
41
|
-
|
44
|
+
assert_equal expected, actual
|
45
|
+
end
|
42
46
|
|
43
|
-
|
47
|
+
def test_empty_all_with_info_line_of_one_string
|
44
48
|
|
45
|
-
|
46
|
-
end
|
49
|
+
specifications = []
|
47
50
|
|
48
|
-
|
51
|
+
stream = StringIO.new
|
49
52
|
|
50
|
-
|
53
|
+
info = 'myprog version'.freeze
|
51
54
|
|
52
|
-
|
55
|
+
CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info
|
53
56
|
|
54
|
-
|
57
|
+
expected = <<EOF_output
|
58
|
+
myprog version
|
59
|
+
USAGE: myprog
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
].freeze
|
61
|
+
EOF_output
|
62
|
+
actual = stream.string
|
59
63
|
|
60
|
-
|
64
|
+
assert_equal expected, actual
|
65
|
+
end
|
61
66
|
|
62
|
-
|
63
|
-
end
|
67
|
+
def test_empty_all_with_info_lines
|
64
68
|
|
65
|
-
|
69
|
+
specifications = []
|
66
70
|
|
67
|
-
|
71
|
+
stream = StringIO.new
|
68
72
|
|
69
|
-
|
73
|
+
info_lines = [
|
70
74
|
|
71
|
-
|
75
|
+
'Synesis Software My Program',
|
76
|
+
'version 1',
|
77
|
+
].freeze
|
72
78
|
|
73
|
-
|
74
|
-
:version
|
75
|
-
].freeze
|
79
|
+
CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info_lines
|
76
80
|
|
77
|
-
|
81
|
+
expected = <<EOF_output
|
82
|
+
Synesis Software My Program
|
83
|
+
version 1
|
84
|
+
USAGE: myprog
|
78
85
|
|
79
|
-
|
80
|
-
|
86
|
+
EOF_output
|
87
|
+
actual = stream.string
|
81
88
|
|
82
|
-
|
89
|
+
assert_equal expected, actual
|
90
|
+
end
|
83
91
|
|
84
|
-
|
92
|
+
def test_empty_all_with_info_lines_including_version
|
85
93
|
|
86
|
-
|
87
|
-
]
|
94
|
+
specifications = []
|
88
95
|
|
89
|
-
|
96
|
+
stream = StringIO.new
|
90
97
|
|
91
|
-
|
98
|
+
info_lines = [
|
92
99
|
|
93
|
-
|
94
|
-
|
100
|
+
'Synesis Software My Program',
|
101
|
+
:version
|
102
|
+
].freeze
|
95
103
|
|
96
|
-
|
104
|
+
CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info_lines, version: [ 1, 0, 1], version_prefix: 'v'
|
97
105
|
|
98
|
-
|
106
|
+
expected = <<EOF_output
|
107
|
+
Synesis Software My Program
|
108
|
+
myprog v1.0.1
|
109
|
+
USAGE: myprog
|
99
110
|
|
100
|
-
|
101
|
-
|
111
|
+
EOF_output
|
112
|
+
actual = stream.string
|
102
113
|
|
103
|
-
|
114
|
+
assert_equal expected, actual
|
115
|
+
end
|
104
116
|
|
105
|
-
|
117
|
+
def test_one_alias_default
|
106
118
|
|
107
|
-
|
108
|
-
|
119
|
+
specifications = [
|
120
|
+
|
121
|
+
CLASP::Flag.Version
|
122
|
+
]
|
123
|
+
|
124
|
+
stream = StringIO.new
|
125
|
+
|
126
|
+
CLASP.show_usage specifications, stream: stream, program_name: 'myprog'
|
127
|
+
|
128
|
+
expected = <<EOF_output
|
129
|
+
USAGE: myprog [ ... flags and options ... ]
|
130
|
+
|
131
|
+
flags/options:
|
132
|
+
|
133
|
+
\t--version
|
134
|
+
\t\t#{CLASP::Flag.Version.help}
|
135
|
+
|
136
|
+
EOF_output
|
137
|
+
actual = stream.string
|
138
|
+
|
139
|
+
assert_equal expected, actual
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_one_alias_all
|
143
|
+
|
144
|
+
specifications = [
|
145
|
+
|
146
|
+
CLASP::Flag.Version
|
147
|
+
]
|
148
|
+
|
149
|
+
stream = StringIO.new
|
150
|
+
|
151
|
+
CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: ''
|
152
|
+
|
153
|
+
expected = <<EOF_output
|
154
|
+
USAGE: myprog
|
155
|
+
|
156
|
+
flags/options:
|
157
|
+
|
158
|
+
\t--version
|
159
|
+
\t\t#{CLASP::Flag.Version.help}
|
160
|
+
|
161
|
+
EOF_output
|
162
|
+
actual = stream.string
|
163
|
+
|
164
|
+
assert_equal expected, actual
|
165
|
+
end
|
109
166
|
end
|
110
167
|
|
data/test/unit/tc_with_action.rb
CHANGED
@@ -10,41 +10,40 @@ require 'test/unit'
|
|
10
10
|
|
11
11
|
class Test_WithAction < Test::Unit::TestCase
|
12
12
|
|
13
|
-
|
13
|
+
def test_flag_with_action
|
14
14
|
|
15
|
-
|
15
|
+
debug = false
|
16
16
|
|
17
|
-
|
17
|
+
specifications = [
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
CLASP.Flag('--debug', alias: '-d') { debug = true }
|
20
|
+
]
|
21
|
+
argv = []
|
22
|
+
args = CLASP.parse argv, specifications
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
assert_equal 0, args.flags.size
|
25
|
+
assert_equal 0, args.options.size
|
26
|
+
assert_equal 0, args.values.size
|
27
27
|
|
28
|
-
|
28
|
+
assert_false debug
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
argv2 = [ '--debug' ]
|
31
|
+
args2 = CLASP.parse argv2, specifications
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
assert_equal 1, args2.flags.size
|
34
|
+
assert_equal 0, args2.options.size
|
35
|
+
assert_equal 0, args2.values.size
|
36
36
|
|
37
|
-
|
37
|
+
assert_false debug
|
38
38
|
|
39
|
-
|
39
|
+
if ix = args2.flags.index('--debug')
|
40
40
|
|
41
|
-
|
41
|
+
flag = args2.flags[ix]
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
flag.argument_specification.action.call(flag, flag.argument_specification)
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
assert_true debug
|
47
|
+
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
data/test/unit/ts_all.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clasp-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.23.0.
|
4
|
+
version: 0.23.0.2
|
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: 2024-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xqsr3
|
@@ -25,8 +25,9 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.38'
|
27
27
|
description: |
|
28
|
-
Command-Line Argument Sorting and Parsing library that provides a powerful
|
29
|
-
|
28
|
+
Command-Line Argument Sorting and Parsing library that provides a powerful abstraction of command-line interpretation facilities.
|
29
|
+
|
30
|
+
CLASP.Ruby is a Ruby port of the popular CLASP (C/C++) library, and provides declarative specification of command-line flags and options, aliasing, flag combination, UNIX de-facto standard flag processing, and a number of utility functions for expressing usage and version information.
|
30
31
|
email: matthew@synesis.com.au
|
31
32
|
executables: []
|
32
33
|
extensions: []
|