docopt / docopt.cpp

C++11 port of docopt
Boost Software License 1.0
1.05k stars 146 forks source link

combining optional arguments not working #85

Closed janwilmans closed 4 years ago

janwilmans commented 7 years ago

In this example:

>DebugViewConsole.exe -d test.dblog

works

>DebugViewConsole.exe -a false

works, however, the combination:

>DebugViewConsole.exe -d test.dblog -a false
Unexpected argument: -d, test.dblog, -a, false

does not work

static const char USAGE[] =
R"(DebugviewConsole )" VERSION_STR
R"(
    Usage: 
        DebugviewConsole [-i <pattern>, --include <pattern>]... [-e <pattern>, --exclude <pattern>]... 
        DebugviewConsole [-cflsqtpnv] [-d <file>]
        DebugviewConsole (-h | --help)
        DebugviewConsole [-a <value>] 
        DebugviewConsole [-x]
        DebugviewConsole [-u]

    Options:
        -h, --help                          show this screen
        -i <pattern>, --include <pattern>   include filter, may be specified multiple times
        -e <pattern>, --exclude <pattern>   exclude filter, may be specified multiple times
        -c              enable console output
        -d <file>       write to .dblog file
        -v              verbose

    Advanced options:
        -a <value>      auto-newline [default: true]
        -f              aggressively flush buffers, if unsure, do not use
        -x              stop all running debugviewconsole instances
        -u              send a UDP test-message, used only for debugging

    Console options:    (no effect on .dblog file)
        -l              prefix line number
        -s              prefix messages with system time
        -q              prefix message with high-precision (<1us) offset from QueryPerformanceCounter
        -t              tab-separated output
        -p              add PID (process ID)
        -n              add process name
)";
janwilmans commented 7 years ago

ok, so the problem here was, that the options I was combining were on listed on the same line in the Usage specification. So this is apparently interpreted as 'not to be used together', but the error message 'Unexpected argument' would be more clear if it said something like 'options cannot be used together '-d , -a '.

The example below works in all combinations that I have tried, however, the -a option changed, so I tested with the combination of -d and -i

static const char USAGE[] =
R"(DebugviewConsole )" VERSION_STR
R"(
    Usage:
        DebugviewConsole [-acflsqtpnv] [-d <file>] [-i <pattern>, --include <pattern>]... [-e <pattern>, --exclude <pattern>]... 
        DebugviewConsole (-h | --help)
        DebugviewConsole [-x]
        DebugviewConsole [-u]

    Options:
        -h, --help                          show this screen
        -i <pattern>, --include <pattern>   include filter, may be specified multiple times
        -e <pattern>, --exclude <pattern>   exclude filter, may be specified multiple times
        -a              auto-newline, most people want this
        -c              enable console output
        -d <file>       write to .dblog file
        -v              verbose

    Console options:    (no effect on .dblog file)
        -l              prefix line number
        -s              prefix messages with system time
        -q              prefix message with high-precision (<1us) offset from QueryPerformanceCounter
        -t              tab-separated output
        -p              add PID (process ID)
        -n              add process name

    Advanced options:
        -f              aggressively flush buffers, if unsure, do not use
        -x              stop all running debugviewconsole instances
        -u              send a UDP test-message, used only for debugging
)";
janwilmans commented 7 years ago

If it is normal behaviour that options from different lines are not to be used together, and there is no interest to improve the error message, this issue can be closed.

indianakernick commented 4 years ago

That looks like expected behaviour to me. There's already a few issues open that discuss error messages.

jaredgrubb commented 4 years ago

Yes, this is expected behavior. This is to support cases where you want certain options to work together (eg, for a given command) and others to not work together.