From 7189d63c209ceb261aec479ec543dce3b1edb19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sat, 1 Dec 2018 17:23:38 -0500 Subject: [PATCH] check for duplicate options --- src/cli.cc | 4 ++++ t/cli.cc | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/cli.cc b/src/cli.cc index 8f1a21a..ec22b0f 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -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."}; diff --git a/t/cli.cc b/t/cli.cc index ccccbf2..33d5383 100644 --- a/t/cli.cc +++ b/t/cli.cc @@ -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)