https://issues.dlang.org/show_bug.cgi?id=16539

--- Comment #1 from Jon Degenhardt <jrdemail2000-dl...@yahoo.com> ---
A similar example, but using an array shared by multiple command line options.
The arrays values are populated in the order specified lexically in the code.
It would be better if they were populated in the order specified at run-time on
the command line.

===== fillorder.d =====

void main(string [] args)
{
    import std.getopt;
    import std.stdio;

    string[] cmdvals;
    try {
        auto r = getopt(
            args,
            "b|bb", "VAL   Append VAL to cmdvals", &cmdvals,
            "a|aa", "VAL   Append VAL to cmdvals", &cmdvals,
            "c|cc", "VAL   Append VAL to cmdvals", &cmdvals,
            );

        if (r.helpWanted) {
            defaultGetoptPrinter(
                "std.getopt array fill order test. Use options multiple times
in different orders.",
                r.options);
            return;
        }
    } catch (Exception exc) {
        stderr.writeln("Error processing command line arguments: ", exc.msg);
        return;
    }

    writeln("cmdvals array: ", cmdvals);
}

==========================

$ dmd fillorder.d
$ ./fillorder -a 1 -b 2 -c 3 -a 4 -b 5 -c 6
cmdvals array: ["2", "5", "1", "4", "3", "6"]

--

Reply via email to