We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 4926f58 + 5ef6e23 commit 0d0ef3cCopy full SHA for 0d0ef3c
3 files changed
command-line-parser.dylan
@@ -480,11 +480,16 @@ end method;
480
define open generic parse-option-value
481
(parameter :: <string>, type :: <type>) => (value :: <object>);
482
483
-// Default method just returns the value.
484
define method parse-option-value
485
- (param :: <string>, type :: <type>) => (value :: <string>)
486
- param
487
-end;
+ (param :: <string>, type :: <type>) => (value :: <object>)
+ block ()
+ // If type happens to have an AS method (for example like <file-locator> does) then
+ // we will automatically support that type.
488
+ as(type, param)
489
+ exception (<error>)
490
+ param
491
+ end
492
+end method;
493
494
// This is essentially for "float or int", which could be <real>, but
495
// <number> is also a natural choice.
tests/command-line-parser-test-suite-library.dylan
@@ -13,6 +13,7 @@ define module command-line-parser-test-suite
13
use command-line-parser;
14
use common-dylan, exclude: { format-to-string };
15
use format;
16
+ use locators;
17
use option-parser-protocol,
18
import: {
19
option-help,
tests/command-line-parser-test-suite.dylan
@@ -187,6 +187,10 @@ define test test-option-type ()
187
help: "x",
188
names: #("repeated-integer"),
189
type: <integer>));
190
+ add-option(parser, make(<parameter-option>,
191
+ help: "x",
192
+ names: #("file-locator"),
193
+ type: <file-locator>));
194
parser
195
end method make-parser;
196
let items = list(list("integer", "123", 123, <integer>),
@@ -198,7 +202,9 @@ define test test-option-type ()
198
202
list("symbol", "foo", #"foo", <symbol>),
199
203
list("number", "123", 123, <integer>),
200
204
list("real", "123", 123, <integer>),
201
- list("string", "bar", "bar", <string>));
205
+ list("string", "bar", "bar", <string>),
206
+ list("file-locator", "/tmp/x", as(<file-locator>, "/tmp/x"),
207
+ <file-locator>));
208
for (item in items)
209
let (name, param, expected-value, expected-type) = apply(values, item);
210
let parser = make-parser();
0 commit comments