check for duplicate options

This commit is contained in:
Frédéric Mangano-Tarumi 2018-12-01 17:23:38 -05:00
parent d67ce423d1
commit 7189d63c20
2 changed files with 7 additions and 0 deletions

View File

@ -67,11 +67,15 @@ ot::status ot::parse_options(int argc, char** argv, ot::options& opt)
opt.print_help = true;
break;
case 'o':
if (!opt.path_out.empty())
return {st::bad_arguments, "Cannot specify --output more than once."};
opt.path_out = optarg;
if (opt.path_out.empty())
return {st::bad_arguments, "Output file path cannot be empty."};
break;
case 'i':
if (opt.inplace != nullptr)
return {st::bad_arguments, "Cannot specify --in-place more than once."};
opt.inplace = optarg == nullptr ? ".otmp" : optarg;
if (strcmp(opt.inplace, "") == 0)
return {st::bad_arguments, "In-place suffix cannot be empty."};

View File

@ -46,6 +46,9 @@ void check_bad_arguments()
error_case({"opustags", "-S", "-"}, "Cannot use standard input as input file when --set-all is specified.",
"set all and read opus from stdin");
error_case({"opustags", "-i", "-"}, "Cannot modify standard input in-place.", "write stdin in-place");
error_case({"opustags", "-o", "x", "--output", "y", "z"},
"Cannot specify --output more than once.", "double output");
error_case({"opustags", "-i", "-i", "z"}, "Cannot specify --in-place more than once.", "double in-place");
}
int main(int argc, char **argv)