From d8c36a3d3f7266a0577c28176d62849c7defb38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Sat, 24 Oct 2020 13:10:47 +0200 Subject: [PATCH] Forbid mixing --edit with non-interactive edition options --- src/cli.cc | 5 ++++- t/cli.cc | 7 ++++--- t/opustags.t | 10 +++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cli.cc b/src/cli.cc index 0c91263..006bdb7 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -141,12 +141,15 @@ ot::status ot::parse_options(int argc, char** argv, ot::options& opt, FILE* comm if (set_all && stdin_as_input) return {st::bad_arguments, "Cannot use standard input as input file when --set-all is specified."}; - if (opt.edit_interactively && (set_all || stdin_as_input || opt.path_out == "-")) + if (opt.edit_interactively && (stdin_as_input || opt.path_out == "-")) return {st::bad_arguments, "Cannot edit interactively when standard input or standard output are already used."}; if (opt.edit_interactively && !opt.path_out.has_value() && !opt.in_place) return {st::bad_arguments, "Cannot edit interactively when no output is specified."}; + if (opt.edit_interactively && (opt.delete_all || !opt.to_add.empty() || !opt.to_delete.empty())) + return {st::bad_arguments, "Cannot mix --edit with -adDsS."}; + if (set_all) { // Read comments from stdin and prepend them to opt.to_add. std::list comments; diff --git a/t/cli.cc b/t/cli.cc index f1a961a..b965852 100644 --- a/t/cli.cc +++ b/t/cli.cc @@ -128,9 +128,6 @@ void check_bad_arguments() "Cannot specify --output more than once.", "double output with first filename empty"); error_case({"opustags", "-e", "-i", "x", "y"}, "Exactly one input file must be specified.", "editing interactively two files at once"); - error_case({"opustags", "--edit", "-S", "x"}, - "Cannot edit interactively when standard input or standard output are already used.", - "editing interactively with --set-all"); error_case({"opustags", "--edit", "-", "-o", "x"}, "Cannot edit interactively when standard input or standard output are already used.", "editing interactively from stdandard intput"); @@ -138,6 +135,10 @@ void check_bad_arguments() "Cannot edit interactively when standard input or standard output are already used.", "editing interactively to stdandard output"); error_case({"opustags", "--edit", "x"}, "Cannot edit interactively when no output is specified.", "editing without output"); + error_case({"opustags", "--edit", "x", "-i", "-a", "X=Y"}, "Cannot mix --edit with -adDsS.", "mixing -e and -a"); + error_case({"opustags", "--edit", "x", "-i", "-d", "X"}, "Cannot mix --edit with -adDsS.", "mixing -e and -d"); + error_case({"opustags", "--edit", "x", "-i", "-D"}, "Cannot mix --edit with -adDsS.", "mixing -e and -D"); + error_case({"opustags", "--edit", "x", "-i", "-S"}, "Cannot mix --edit with -adDsS.", "mixing -e and -S"); } static void check_delete_comments() diff --git a/t/opustags.t b/t/opustags.t index 9308ef1..e1969a0 100755 --- a/t/opustags.t +++ b/t/opustags.t @@ -226,13 +226,13 @@ unlink('out2.opus'); #################################################################################################### # Interactive edition -$ENV{EDITOR} = 'sed -i -e y/a/A/'; -is_deeply(opustags(qw(gobble.opus --add artist=aaah -o screaming.opus -e)), ['', '', 0], 'edit a file with EDITOR'); -is(md5('screaming.opus'), '682229df1df6b0ca147e2778737d449e', 'the tags were modified'); +$ENV{EDITOR} = 'sed -i -e y/aeiou/AEIOU/'; +is_deeply(opustags(qw(gobble.opus -o screaming.opus -e)), ['', '', 0], 'edit a file with EDITOR'); +is(md5('screaming.opus'), '56e85ccaa83a13c15576d75bbd6d835f', 'the tags were modified'); $ENV{EDITOR} = 'true'; -is_deeply(opustags(qw(--add mystery=1 -i screaming.opus -e)), ['', "Cancelling edition because the tags file was not modified.\n", 256], 'close -e without saving'); -is(md5('screaming.opus'), '682229df1df6b0ca147e2778737d449e', 'the tags were not modified'); +is_deeply(opustags(qw(-i screaming.opus -e)), ['', "Cancelling edition because the tags file was not modified.\n", 256], 'close -e without saving'); +is(md5('screaming.opus'), '56e85ccaa83a13c15576d75bbd6d835f', 'the tags were not modified'); unlink('screaming.opus');