Allow passing settings to JavaScript
This commit is contained in:
parent
e69278634f
commit
d248c63279
|
@ -84,6 +84,7 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg, Argumen
|
|||
, layoutOnlyArg("layout-only", 'l', "confirms layout-only changes")
|
||||
, preserveModificationTimeArg("preserve-modification-time", '\0', "preserves the file's modification time")
|
||||
, jsArg("java-script", 'j', "modifies tag fields via the specified JavaScript", { "path" })
|
||||
, jsSettingsArg("script-settings", '\0', "passes settings to the JavaScript specified via --java-script", { "key=value" })
|
||||
, setTagInfoArg("set", 's', "sets the specified tag information and attachments")
|
||||
{
|
||||
docTitleArg.setRequiredValueCount(Argument::varValueCount);
|
||||
|
@ -122,6 +123,8 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg, Argumen
|
|||
valuesArg.setValueCompletionBehavior(ValueCompletionBehavior::PreDefinedValues | ValueCompletionBehavior::AppendEquationSign);
|
||||
outputFilesArg.setRequiredValueCount(Argument::varValueCount);
|
||||
jsArg.setValueCompletionBehavior(ValueCompletionBehavior::Files);
|
||||
jsSettingsArg.setValueCompletionBehavior(ValueCompletionBehavior::AppendEquationSign);
|
||||
jsSettingsArg.setRequiredValueCount(Argument::varValueCount);
|
||||
setTagInfoArg.setCallback(std::bind(Cli::setTagInfo, std::cref(*this)));
|
||||
setTagInfoArg.setExample(PROJECT_NAME
|
||||
" set title=\"Title of \"{1st,2nd,3rd}\" file\" title=\"Title of \"{4..16}\"th file\" album=\"The Album\" -f /some/dir/*.m4a\n" PROJECT_NAME
|
||||
|
@ -137,7 +140,7 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg, Argumen
|
|||
&id3v2UsageArg, &id3InitOnCreateArg, &id3TransferOnRemovalArg, &mergeMultipleSuccessiveTagsArg, &id3v2VersionArg, &encodingArg,
|
||||
&removeTargetArg, &addAttachmentArg, &updateAttachmentArg, &removeAttachmentArg, &removeExistingAttachmentsArg, &minPaddingArg,
|
||||
&maxPaddingArg, &prefPaddingArg, &tagPosArg, &indexPosArg, &forceRewriteArg, &backupDirArg, &layoutOnlyArg, &preserveModificationTimeArg,
|
||||
&jsArg, &verboseArg, &pedanticArg, &quietArg, &outputFilesArg });
|
||||
&jsArg, &jsSettingsArg, &verboseArg, &pedanticArg, &quietArg, &outputFilesArg });
|
||||
}
|
||||
|
||||
} // namespace Cli
|
||||
|
|
|
@ -548,6 +548,19 @@ JavaScriptProcessor::JavaScriptProcessor(const SetTagInfoArgs &args)
|
|||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// assign settings specified via CLI argument
|
||||
auto settings = engine.newObject();
|
||||
if (args.jsSettingsArg.isPresent()) {
|
||||
for (const auto *const setting : args.jsSettingsArg.values()) {
|
||||
if (const auto *const value = std::strchr(setting, '=')) {
|
||||
settings.setProperty(QString::fromUtf8(setting, value - setting), QJSValue(QString::fromUtf8(value + 1)));
|
||||
} else {
|
||||
settings.setProperty(QString::fromUtf8(setting), QJSValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
engine.globalObject().setProperty(QStringLiteral("settings"), settings);
|
||||
|
||||
// print warnings
|
||||
printDiagMessages(diag, "Diagnostic messages:", args.verboseArg.isPresent(), &args.pedanticArg);
|
||||
diag.clear();
|
||||
|
|
|
@ -49,6 +49,7 @@ struct SetTagInfoArgs {
|
|||
CppUtilities::ConfigValueArgument layoutOnlyArg;
|
||||
CppUtilities::ConfigValueArgument preserveModificationTimeArg;
|
||||
CppUtilities::ConfigValueArgument jsArg;
|
||||
CppUtilities::ConfigValueArgument jsSettingsArg;
|
||||
CppUtilities::OperationArgument setTagInfoArg;
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ export function main(file) {
|
|||
file.applyChanges();
|
||||
|
||||
// return a falsy value to skip the file after all
|
||||
return false;
|
||||
return !isTruthy(settings.dryRun);
|
||||
}
|
||||
|
||||
const mainTextFields = ["title", "artist", "album"];
|
||||
|
@ -20,6 +20,10 @@ function isString(value) {
|
|||
return typeof(value) === "string" || value instanceof String;
|
||||
}
|
||||
|
||||
function isTruthy(value) {
|
||||
return value && value !== "false" && value !== "0";
|
||||
}
|
||||
|
||||
function logTagInfo(file, tag) {
|
||||
// log tag type and supported fields
|
||||
const fields = tag.fields;
|
||||
|
|
Loading…
Reference in New Issue