Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions command-line-parser.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,16 @@ end method;
define open generic parse-option-value
(parameter :: <string>, type :: <type>) => (value :: <object>);

// Default method just returns the value.
define method parse-option-value
(param :: <string>, type :: <type>) => (value :: <string>)
param
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.
as(type, param)
exception (<error>)
param
end
end method;

// This is essentially for "float or int", which could be <real>, but
// <number> is also a natural choice.
Expand Down
1 change: 1 addition & 0 deletions tests/command-line-parser-test-suite-library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define module command-line-parser-test-suite
use command-line-parser;
use common-dylan, exclude: { format-to-string };
use format;
use locators;
use option-parser-protocol,
import: {
option-help,
Expand Down
8 changes: 7 additions & 1 deletion tests/command-line-parser-test-suite.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ define test test-option-type ()
help: "x",
names: #("repeated-integer"),
type: <integer>));
add-option(parser, make(<parameter-option>,
help: "x",
names: #("file-locator"),
type: <file-locator>));
parser
end method make-parser;
let items = list(list("integer", "123", 123, <integer>),
Expand All @@ -198,7 +202,9 @@ define test test-option-type ()
list("symbol", "foo", #"foo", <symbol>),
list("number", "123", 123, <integer>),
list("real", "123", 123, <integer>),
list("string", "bar", "bar", <string>));
list("string", "bar", "bar", <string>),
list("file-locator", "/tmp/x", as(<file-locator>, "/tmp/x"),
<file-locator>));
for (item in items)
let (name, param, expected-value, expected-type) = apply(values, item);
let parser = make-parser();
Expand Down