cli: Add --quiet flag to set operation

This commit is contained in:
Martchus 2021-05-27 18:56:42 +02:00
parent 818b9a60f6
commit 9e0ce80c8c
3 changed files with 17 additions and 9 deletions

View File

@ -32,6 +32,7 @@ namespace Cli {
SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg)
: filesArg(filesArg)
, verboseArg(verboseArg)
, quietArg("quiet", 'q', "suppress printing progress information")
, docTitleArg("doc-title", 'd', "specifies the document title (has no affect if not supported by the container)",
{ "title of first segment", "title of second segment" })
, removeOtherFieldsArg(
@ -128,10 +129,11 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg)
" set mkv:CUSTOM_FIELD=\"Matroska-only\" vorbis:CUSTOM_FIELD=\"Vorbis-only\" mp4:©ust=\"MP4-only\" \\\n"
" -f file.mkv file.ogg file.m4a\n"
"For more examples and detailed descriptions see " APP_URL "#writing-tags");
setTagInfoArg.setSubArguments({ &valuesArg, &filesArg, &docTitleArg, &removeOtherFieldsArg, &treatUnknownFilesAsMp3FilesArg, &id3v1UsageArg,
&id3v2UsageArg, &id3InitOnCreateArg, &id3TransferOnRemovalArg, &mergeMultipleSuccessiveTagsArg, &id3v2VersionArg, &encodingArg,
&removeTargetArg, &addAttachmentArg, &updateAttachmentArg, &removeAttachmentArg, &removeExistingAttachmentsArg, &minPaddingArg,
&maxPaddingArg, &prefPaddingArg, &tagPosArg, &indexPosArg, &forceRewriteArg, &backupDirArg, &layoutOnlyArg, &verboseArg, &outputFilesArg });
setTagInfoArg.setSubArguments(
{ &valuesArg, &filesArg, &docTitleArg, &removeOtherFieldsArg, &treatUnknownFilesAsMp3FilesArg, &id3v1UsageArg, &id3v2UsageArg,
&id3InitOnCreateArg, &id3TransferOnRemovalArg, &mergeMultipleSuccessiveTagsArg, &id3v2VersionArg, &encodingArg, &removeTargetArg,
&addAttachmentArg, &updateAttachmentArg, &removeAttachmentArg, &removeExistingAttachmentsArg, &minPaddingArg, &maxPaddingArg,
&prefPaddingArg, &tagPosArg, &indexPosArg, &forceRewriteArg, &backupDirArg, &layoutOnlyArg, &verboseArg, &quietArg, &outputFilesArg });
}
} // namespace Cli
@ -148,7 +150,7 @@ int main(int argc, char *argv[])
ConfigValueArgument timeSpanFormatArg("time-span-format", '\0', "specifies the output format for time spans", { "measures/colons/seconds" });
timeSpanFormatArg.setPreDefinedCompletionValues("measures colons seconds");
// verbose option
ConfigValueArgument verboseArg("verbose", 'v', "be verbose");
ConfigValueArgument verboseArg("verbose", 'v', "be verbose, print debug and info messages");
// input/output file/files
ConfigValueArgument fileArg("file", 'f', "specifies the path of the file to be opened", { "path" });
ConfigValueArgument defaultFileArg(fileArg);

View File

@ -561,6 +561,7 @@ void setTagInfo(const SetTagInfoArgs &args)
}
// iterate through all specified files
const auto quiet = args.quietArg.isPresent();
unsigned int fileIndex = 0;
static string context("setting tags");
for (const char *file : args.filesArg.values()) {
@ -568,7 +569,9 @@ void setTagInfo(const SetTagInfoArgs &args)
AbortableProgressFeedback parsingProgress; // FIXME: actually use the progress object
try {
// parse tags and tracks (tracks are relevent because track meta-data such as language can be changed as well)
cout << TextAttribute::Bold << "Setting tag information for \"" << file << "\" ..." << Phrases::EndFlush;
if (!quiet) {
cout << TextAttribute::Bold << "Setting tag information for \"" << file << "\" ..." << Phrases::EndFlush;
}
fileInfo.setPath(std::string(file));
fileInfo.parseContainerFormat(diag, parsingProgress);
fileInfo.parseTags(diag, parsingProgress);
@ -850,15 +853,17 @@ void setTagInfo(const SetTagInfoArgs &args)
fileInfo.setSaveFilePath(currentOutputFile != noMoreOutputFiles ? string(*currentOutputFile) : string());
try {
// create handler for progress updates and aborting
AbortableProgressFeedback applyProgress(logNextStep, logStepPercentage);
const InterruptHandler handler(bind(&AbortableProgressFeedback::tryToAbort, ref(applyProgress)));
auto applyProgress = quiet ? AbortableProgressFeedback() : AbortableProgressFeedback(logNextStep, logStepPercentage);
const auto handler = InterruptHandler(std::bind(&AbortableProgressFeedback::tryToAbort, std::ref(applyProgress)));
// apply changes
fileInfo.applyChanges(diag, applyProgress);
// notify about completion
finalizeLog();
cout << " - Changes have been applied." << endl;
if (!quiet) {
cout << " - Changes have been applied." << endl;
}
} catch (const TagParser::OperationAbortedException &) {
finalizeLog();
cerr << Phrases::Warning << "The operation has been aborted." << Phrases::EndFlush;

View File

@ -13,6 +13,7 @@ struct SetTagInfoArgs {
SetTagInfoArgs(CppUtilities::Argument &filesArg, CppUtilities::Argument &verboseArg);
CppUtilities::Argument &filesArg;
CppUtilities::Argument &verboseArg;
CppUtilities::ConfigValueArgument quietArg;
CppUtilities::ConfigValueArgument docTitleArg;
CppUtilities::ConfigValueArgument removeOtherFieldsArg;
CppUtilities::ConfigValueArgument treatUnknownFilesAsMp3FilesArg;