inplace -> in_place

This commit is contained in:
Frédéric Mangano-Tarumi 2018-12-01 17:39:27 -05:00
parent 1e69e89ff9
commit 614bd6379b
4 changed files with 13 additions and 13 deletions

View File

@ -53,7 +53,7 @@ The input file will be read, its tags edited, then written to the specified outp
The output file cant be the same as the input file.
.TP
.B \-i, \-\-in-place\fR[=\fP\fISUFFIX\fP\fR]\fP
Use this when you want to modify the input file in-place. opustags will create a temporary output
Use this when you want to modify the input file in place. opustags will create a temporary output
file with the specified suffix (.otmp by default), and move it to the location of the input file on
success. If a file with the same name as the temporary file already exists, it will be overwritten
without warning.

View File

@ -74,10 +74,10 @@ ot::status ot::parse_options(int argc, char** argv, ot::options& opt)
return {st::bad_arguments, "Output file path cannot be empty."};
break;
case 'i':
if (opt.inplace != nullptr)
if (opt.in_place != nullptr)
return {st::bad_arguments, "Cannot specify --in-place more than once."};
opt.inplace = optarg == nullptr ? ".otmp" : optarg;
if (strcmp(opt.inplace, "") == 0)
opt.in_place = optarg == nullptr ? ".otmp" : optarg;
if (strcmp(opt.in_place, "") == 0)
return {st::bad_arguments, "In-place suffix cannot be empty."};
break;
case 'y':
@ -117,13 +117,13 @@ ot::status ot::parse_options(int argc, char** argv, ot::options& opt)
opt.path_in = argv[optind];
if (opt.path_in.empty())
return {st::bad_arguments, "Input file path cannot be empty."};
if (opt.inplace != nullptr && !opt.path_out.empty())
if (opt.in_place != nullptr && !opt.path_out.empty())
return {st::bad_arguments, "Cannot combine --in-place and --output."};
if (opt.path_in == "-" && opt.set_all)
return {st::bad_arguments,
"Cannot use standard input as input file when --set-all is specified."};
if (opt.path_in == "-" && opt.inplace)
return {st::bad_arguments, "Cannot modify standard input in-place."};
if (opt.path_in == "-" && opt.in_place)
return {st::bad_arguments, "Cannot modify standard input in place."};
return st::ok;
}
@ -265,7 +265,7 @@ ot::status ot::run(const ot::options& opt)
return st::ok;
}
std::string path_out = opt.inplace ? opt.path_in + opt.inplace : opt.path_out;
std::string path_out = opt.in_place ? opt.path_in + opt.in_place : opt.path_out;
if (!path_out.empty() && same_file(opt.path_in, path_out))
return {ot::st::fatal_error, "Input and output files are the same"};
@ -312,7 +312,7 @@ ot::status ot::run(const ot::options& opt)
return rc;
}
if (opt.inplace) {
if (opt.in_place) {
if (rename(path_out.c_str(), opt.path_in.c_str()) == -1)
return {ot::st::fatal_error,
"Could not move the result to '" + opt.path_in + "': " + strerror(errno)};

View File

@ -379,7 +379,7 @@ struct options {
*
* Option: --in-place
*/
const char* inplace = nullptr;
const char* in_place = nullptr;
/**
* By default, opustags won't overwrite the output file if it already exists.
*

View File

@ -34,13 +34,13 @@ void check_good_arguments()
throw failure("did not catch --help");
opt = parse({"opustags", "x", "--output", "y", "-D", "-s", "X=Y Z"});
if (opt.inplace != nullptr || opt.path_in != "x" || opt.path_out != "y" || !opt.delete_all ||
if (opt.in_place != nullptr || opt.path_in != "x" || opt.path_out != "y" || !opt.delete_all ||
opt.to_delete.size() != 1 || opt.to_delete[0] != "X=Y Z" ||
opt.to_add.size() != 1 || opt.to_add[0] != "X=Y Z")
throw failure("unexpected option parsing result for case #1");
opt = parse({"opustags", "-S", "-y", "x", "-S", "-a", "x=y z", "-i"});
if (opt.inplace == nullptr || opt.path_in != "x" || !opt.path_out.empty() ||
if (opt.in_place == nullptr || opt.path_in != "x" || !opt.path_out.empty() ||
!opt.set_all || !opt.overwrite || opt.to_delete.size() != 0 ||
opt.to_add.size() != 1 || opt.to_add[0] != "x=y z")
throw failure("unexpected option parsing result for case #2");
@ -73,7 +73,7 @@ void check_bad_arguments()
error_case({"opustags", "-i", "-o", "/dev/null", "-"}, "Cannot combine --in-place and --output.", "in-place + output");
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", "-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");