tools: abort at unknown cmdline parameters
This change makes all C++-based tools in tools/ abort when they encounter an unknown commandline parameter (both option or non-option). This has already caused some confusion, as in some cases unexpected behaviour can be the result. For example, "prune-trace -t mytrace.tc -d database" up to now ignored the "-t" parameter, took "mytrace.tc" as the first non-option parameter (and ignored it); as no option parameter may follow the non-option parameters, all other options were ignored as well. Change-Id: Ia0812a518c4760fa28ed54979c81f43fa7aa096e
This commit is contained in:
@ -49,7 +49,8 @@ int main(int argc, char *argv[])
|
||||
Trace_Event ev;
|
||||
|
||||
CommandLine &cmd = CommandLine::Inst();
|
||||
cmd.addOption("", "", Arg::None, "usage: dump-trace [options] tracefile.tc");
|
||||
CommandLine::option_handle UNKNOWN =
|
||||
cmd.addOption("", "", Arg::None, "usage: dump-trace [options] tracefile.tc");
|
||||
CommandLine::option_handle HELP =
|
||||
cmd.addOption("h", "help", Arg::None, "-h/--help \tPrint usage and exit");
|
||||
CommandLine::option_handle STATS =
|
||||
@ -67,7 +68,13 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (cmd[HELP] || cmd.parser()->nonOptionsCount() != 1) {
|
||||
if (cmd[HELP] || cmd[UNKNOWN] || cmd.parser()->nonOptionsCount() != 1) {
|
||||
for (option::Option* opt = cmd[UNKNOWN]; opt; opt = opt->next()) {
|
||||
std::cerr << "Unknown option: " << opt->name << "\n";
|
||||
}
|
||||
for (int i = 1; i < cmd.parser()->nonOptionsCount(); ++i) {
|
||||
std::cerr << "Unknown non-option: " << cmd.parser()->nonOption(i) << "\n";
|
||||
}
|
||||
cmd.printUsage();
|
||||
if (cmd[HELP]) {
|
||||
exit(0);
|
||||
|
||||
Reference in New Issue
Block a user