mirror of
https://github.com/fmang/opustags.git
synced 2024-11-06 05:27:23 +01:00
Forbid mixing --edit with non-interactive edition options
This commit is contained in:
parent
ba2236facb
commit
d8c36a3d3f
@ -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<std::string> comments;
|
||||
|
7
t/cli.cc
7
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()
|
||||
|
10
t/opustags.t
10
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');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user