commandNameArgument

Extract the command name from the argument list

string
commandNameArgument
(
ref string[] args
)

Parameters

args string[]

a list of string arguments that will be processed

Return Value

Type: string

The command name that was found (may be null).

Examples

test extractCommandNameArgument usage

{
    string[] args;
    /// It returns an empty string on when there are no args
    assert(commandNameArgument(args) is null);
    assert(!args.length);
}

{
    string[] args = [ "test" ];
    /// It returns the first argument when it does not start with `-`
    assert(commandNameArgument(args) == "test");
    /// There is nothing to extract when the arguments only contain the `test` cmd
    assert(!args.length);
}

{
    string[] args = [ "-a", "-b" ];
    /// It extracts two arguments when they are not a command
    assert(commandNameArgument(args) is null);
    assert(args == ["-a", "-b"]);
}

{
    string[] args = [ "-test" ];
    /// It returns the an empty string when it starts with `-`
    assert(commandNameArgument(args) is null);
    assert(args.length == 1);
}

{
    string[] args = [ "foo:bar" ];
    // Sub package names are ignored as command names
    assert(commandNameArgument(args) is null);
    assert(args.length == 1);
    args[0] = ":foo";
    assert(commandNameArgument(args) is null);
    assert(args.length == 1);
}

Meta