andrey-zherikov / argparse

Parser for command-line arguments
https://andrey-zherikov.github.io/argparse/
Boost Software License 1.0
30 stars 6 forks source link

A lone `-` should be treated as a regular positional argument #120

Closed SirNickolas closed 8 months ago

SirNickolas commented 9 months ago

It is a common idiom to accept a - parameter meaning stdin. E.g., cat - reads its whole stdin and sends it to stdout. However, argparse currently treats it as a named parameter, even though NamedArgument("") is not allowed—so it cannot be accessed in any way.

import argparse;

struct T {
    @NamedArgument bool c;
    @PositionalArgument(0) string fileName;
}

void main() {
    assert(CLI!T.parseArgs!((T t) { assert(t == T(true, "-")); })(["-", "-c"]) == 0);
}