argNameAndValue

Splits the argument and its optional value. This function is public in order to document the possible syntaxes of an argument.

Grammar: Identifier | '-' Character IdentifierOrValue | '-' Character ('=' IdentifierOrValue)? | '--' Identifier ('=' IdentifierOrValue)? ;

string[2]
argNameAndValue
(
S = string
)
(
const auto ref S s
)
in { assert (s.length); if (s[0] == '-') assert (s.length >= 2, "minimal length of an hyphenized argument is 2 (-<letter>)"); }

Return Value

Type: string[2]

An array of two strings. The first is always set, it represents the argument name, including the hyphens. The second, optional is its associated value.

Examples

Accepted syntax

1 assert("-a".argNameAndValue == ["-a", ""]);
2 assert("cmd".argNameAndValue == ["cmd", ""]);
3 assert("-tTRUE".argNameAndValue == ["-t", "TRUE"]);
4 assert("-a=true".argNameAndValue == ["-a", "true"]);
5 assert("--a=42".argNameAndValue == ["--a", "42"]);
6 assert("command".argNameAndValue == ["command", ""]);

Invalid syntax

1 import std.exception: assertThrown;
2 import core.exception: AssertError;
3 assertThrown!AssertError("-".argNameAndValue);
4 assertThrown!AssertError("".argNameAndValue);
5 //assertThrown!AssertError("--".argNameAndValue);

Meta