author | Jan Vrany <jan.vrany@labware.com> |
Mon, 29 Nov 2021 23:00:04 +0000 | |
branch | jv |
changeset 25437 | 622824e701ea |
parent 23107 | 40173e082cbc |
permissions | -rw-r--r-- |
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
1 |
" |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
23107 | 3 |
COPYRIGHT (c) 2009 Jan Vrany |
4 |
COPYRIGHT (c) 2016 Jan Vrany |
|
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
5 |
All Rights Reserved |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
6 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
7 |
This software is furnished under a license and may be used |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
8 |
only in accordance with the terms of that license and with the |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
9 |
inclusion of the above copyright notice. This software may not |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
10 |
be provided or otherwise made available to, or used by, any |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
11 |
other person. No title to or ownership of the software is |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
12 |
hereby transferred. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
13 |
" |
13402 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
17340 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
13939 | 18 |
TestCase subclass:#CmdLineParserTest |
13402 | 19 |
instanceVariableNames:'optionA optionB optionBValue' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'System-Support-Command line' |
|
23 |
! |
|
24 |
||
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
25 |
!CmdLineParserTest class methodsFor:'documentation'! |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
26 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
27 |
copyright |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
28 |
" |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
29 |
COPYRIGHT (c) 2006 by eXept Software AG |
23107 | 30 |
COPYRIGHT (c) 2009 Jan Vrany |
31 |
COPYRIGHT (c) 2016 Jan Vrany |
|
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
32 |
All Rights Reserved |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
33 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
34 |
This software is furnished under a license and may be used |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
35 |
only in accordance with the terms of that license and with the |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
36 |
inclusion of the above copyright notice. This software may not |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
37 |
be provided or otherwise made available to, or used by, any |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
38 |
other person. No title to or ownership of the software is |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
39 |
hereby transferred. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
40 |
" |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
41 |
! ! |
13402 | 42 |
|
17340 | 43 |
!CmdLineParserTest class methodsFor:'queries'! |
44 |
||
45 |
coveredClassNames |
|
46 |
^ #( |
|
47 |
'CmdLineOption' |
|
48 |
'CmdLineOptionError' |
|
49 |
'CmdLineParser' |
|
50 |
) |
|
51 |
! ! |
|
52 |
||
13402 | 53 |
!CmdLineParserTest methodsFor:'accessing'! |
54 |
||
55 |
cmdlineOptionA |
|
56 |
||
57 |
^CmdLineOption new |
|
58 |
short: $a; |
|
59 |
long: 'option-a'; |
|
60 |
description: 'option a with no arg'; |
|
61 |
action:[optionA := true] |
|
62 |
||
63 |
"Created: / 28-01-2009 / 11:56:28 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
64 |
"Modified: / 08-06-2009 / 14:34:00 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
65 |
! |
|
66 |
||
67 |
cmdlineOptionB |
|
68 |
||
69 |
^CmdLineOption new |
|
70 |
short: $b; |
|
71 |
long: 'option-b'; |
|
72 |
description: 'option b with one arg'; |
|
73 |
action:[:value | optionB := true. optionBValue := value] |
|
74 |
||
75 |
"Created: / 28-01-2009 / 12:01:43 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
76 |
"Modified: / 08-06-2009 / 14:33:50 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
77 |
! ! |
|
78 |
||
79 |
!CmdLineParserTest methodsFor:'initialization'! |
|
80 |
||
81 |
setUp |
|
82 |
||
83 |
optionA := optionB := false. |
|
84 |
optionBValue := nil |
|
85 |
||
86 |
"Created: / 28-01-2009 / 12:01:01 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
87 |
! ! |
|
88 |
||
89 |
!CmdLineParserTest methodsFor:'tests'! |
|
90 |
||
91 |
test_01 |
|
92 |
||
93 |
CmdLineParser |
|
94 |
parse: #('-a') |
|
95 |
for: self. |
|
96 |
||
97 |
self assert: optionA. |
|
98 |
self deny: optionB. |
|
99 |
||
100 |
"Created: / 28-01-2009 / 14:19:18 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
101 |
"Modified: / 29-05-2009 / 15:47:19 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
102 |
! |
|
103 |
||
104 |
test_02 |
|
105 |
||
106 |
CmdLineParser |
|
107 |
parse: #('--option-a') |
|
108 |
for: self. |
|
109 |
||
110 |
self assert: optionA. |
|
111 |
self deny: optionB. |
|
112 |
||
113 |
"Created: / 28-01-2009 / 14:19:38 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
114 |
"Modified: / 29-05-2009 / 15:47:30 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
115 |
! |
|
116 |
||
117 |
test_04a |
|
118 |
||
119 |
CmdLineParser |
|
120 |
parse: #('--option-b= value') |
|
121 |
for: self. |
|
122 |
||
123 |
self deny: optionA. |
|
124 |
self assert: optionB. |
|
125 |
self assert: optionBValue = ' value' |
|
126 |
||
127 |
"Created: / 30-01-2009 / 10:43:40 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
128 |
"Modified: / 29-05-2009 / 15:47:34 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
129 |
! |
|
130 |
||
131 |
test_04b |
|
132 |
||
133 |
self |
|
134 |
should:[CmdLineParser parse: #('--option-b') for: self] |
|
135 |
raise: CmdLineOptionError |
|
136 |
||
137 |
"Created: / 30-01-2009 / 10:43:37 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
138 |
"Modified: / 29-05-2009 / 15:47:39 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
139 |
! |
|
140 |
||
141 |
test_04c |
|
142 |
||
143 |
CmdLineParser parse: #('--option-b=') for: self. |
|
144 |
||
145 |
self deny: optionA. |
|
146 |
self assert: optionB. |
|
147 |
self assert: optionBValue = '' |
|
148 |
||
149 |
"Created: / 30-01-2009 / 10:44:20 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
150 |
"Modified: / 29-05-2009 / 15:47:44 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
151 |
! |
|
152 |
||
153 |
test_05 |
|
154 |
||
155 |
CmdLineParser |
|
156 |
parse: #('-b' 'value') |
|
157 |
for: self. |
|
158 |
||
159 |
self deny: optionA. |
|
160 |
self assert: optionB. |
|
161 |
self assert: optionBValue = 'value'. |
|
162 |
||
163 |
"Created: / 03-02-2009 / 17:38:51 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
164 |
"Modified: / 29-05-2009 / 15:47:50 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
165 |
! |
|
166 |
||
167 |
test_06 |
|
168 |
||
169 |
CmdLineParser |
|
170 |
parse: #('-a' '-b' 'value') |
|
171 |
for: self. |
|
172 |
||
173 |
self assert: optionA. |
|
174 |
self assert: optionB. |
|
175 |
self assert: optionBValue = 'value'. |
|
176 |
||
177 |
"Created: / 03-02-2009 / 17:39:54 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
178 |
"Modified: / 29-05-2009 / 15:47:56 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
179 |
! |
|
180 |
||
181 |
test_07 |
|
182 |
||
183 |
CmdLineParser |
|
184 |
parse: #('-ab' 'value') |
|
185 |
for: self. |
|
186 |
||
187 |
self assert: optionA. |
|
188 |
self assert: optionB. |
|
189 |
self assert: optionBValue = 'value'. |
|
190 |
||
191 |
"Created: / 03-02-2009 / 17:40:04 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
192 |
"Modified: / 29-05-2009 / 15:48:02 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
193 |
! |
|
194 |
||
195 |
test_08 |
|
196 |
||
197 |
| rest | |
|
198 |
rest := CmdLineParser |
|
199 |
parse: #('-a' '/tmp/abc.txt') |
|
200 |
for: self. |
|
201 |
||
202 |
self assert: optionA. |
|
203 |
self assert: optionB not. |
|
204 |
self assert: rest asArray = #('/tmp/abc.txt') |
|
205 |
||
206 |
"Created: / 08-06-2009 / 14:51:54 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
207 |
! |
|
208 |
||
209 |
test_09 |
|
210 |
||
211 |
| rest | |
|
212 |
rest := CmdLineParser |
|
213 |
parse: #('/tmp/abc.txt') |
|
214 |
for: self. |
|
215 |
||
216 |
self assert: optionA not. |
|
217 |
self assert: optionB not. |
|
218 |
self assert: rest asArray = #('/tmp/abc.txt') |
|
219 |
||
220 |
"Created: / 08-06-2009 / 14:52:13 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
19988
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
221 |
! |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
222 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
223 |
test_10 |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
224 |
| option | |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
225 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
226 |
option := CmdLineOption new spec:$a. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
227 |
self assert: option short == $a. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
228 |
self assert: option long isNil. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
229 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
230 |
option := CmdLineOption new spec:'-a'. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
231 |
self assert: option short == $a. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
232 |
self assert: option long isNil. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
233 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
234 |
option := CmdLineOption new spec:'add'. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
235 |
self assert: option short isNil. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
236 |
self assert: option long = 'add'. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
237 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
238 |
option := CmdLineOption new spec:'--add'. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
239 |
self assert: option short isNil. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
240 |
self assert: option long = 'add'. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
241 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
242 |
option := CmdLineOption new spec:#('-a' '--add'). |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
243 |
self assert: option short == $a. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
244 |
self assert: option long = 'add'. |
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
245 |
|
148721e96482
Added convenience methods to build CmdLineOptions.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18120
diff
changeset
|
246 |
"Created: / 14-06-2016 / 06:58:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
20076
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
247 |
! |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
248 |
|
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
249 |
test_11 |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
250 |
|
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
251 |
| rest | |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
252 |
rest := CmdLineParser new |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
253 |
ignoreUnknownOptions: true; |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
254 |
parse: #('--ignored-option' '/tmp/abc.txt') |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
255 |
for: self. |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
256 |
|
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
257 |
self assert: optionA not. |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
258 |
self assert: optionB not. |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
259 |
self assert: rest asArray = #('--ignored-option' '/tmp/abc.txt') |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
260 |
|
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
261 |
"Created: / 29-06-2016 / 00:15:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
20077
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
262 |
! |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
263 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
264 |
test_12a |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
265 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
266 |
| parser longOptionValue | |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
267 |
parser := CmdLineParser new |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
268 |
on: #('-l' '--long-option=VALUE') do:[:value | longOptionValue := value ]; |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
269 |
yourself. |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
270 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
271 |
parser parse:#('-l' 'v1'). |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
272 |
self assert: longOptionValue = 'v1'. |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
273 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
274 |
parser parse:#('--long-option=v2'). |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
275 |
self assert: longOptionValue = 'v2'. |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
276 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
277 |
"Created: / 29-06-2016 / 17:07:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
278 |
! |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
279 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
280 |
test_12b |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
281 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
282 |
| parser longOptionValue | |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
283 |
parser := CmdLineParser new |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
284 |
on: #('-l' '--long-option VALUE') do:[:value | longOptionValue := value ]; |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
285 |
yourself. |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
286 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
287 |
parser parse:#('-l' 'v1'). |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
288 |
self assert: longOptionValue = 'v1'. |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
289 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
290 |
parser parse:#('--long-option' 'v2'). |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
291 |
self assert: longOptionValue = 'v2'. |
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
292 |
|
e0e720fce465
CmdLineParser refactored to allow both `--long-option=value` and `--long-option value` forms
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20076
diff
changeset
|
293 |
"Created: / 29-06-2016 / 18:43:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
13402 | 294 |
! ! |
295 |
||
296 |
!CmdLineParserTest class methodsFor:'documentation'! |
|
297 |
||
13939 | 298 |
version |
17340 | 299 |
^'$Header: /cvs/stx/stx/libbasic/CmdLineParserTest.st,v 1.4 2015-01-29 19:22:05 cg Exp $' |
20076
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
300 |
! |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
301 |
|
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
302 |
version_HG |
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
303 |
|
ff2f4d06a2fa
CmdLineParser refactored and added an option to ignore unknown options
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19988
diff
changeset
|
304 |
^ '$Changeset: <not expanded> $' |
13402 | 305 |
! ! |
17340 | 306 |