cli: Allow to set backup path
This commit is contained in:
parent
5320ef0660
commit
82ccb9b9f3
|
@ -55,6 +55,7 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg) :
|
|||
forceRewriteArg("force-rewrite", '\0', "forces the file to rewritten from the scratch which ensures a backup is created and the preferred padding is used"),
|
||||
valuesArg("values", 'n', "specifies the values to be set"),
|
||||
outputFilesArg("output-files", 'o', "specifies the output files; if present, the files specified with --files will not be modified"),
|
||||
backupDirArg("temp-dir", '\0', "specifies the directory for temporary/backup files", {"path"}),
|
||||
setTagInfoArg("set", 's', "sets the specified tag information and attachments")
|
||||
{
|
||||
docTitleArg.setCombinable(true);
|
||||
|
@ -150,7 +151,7 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg) :
|
|||
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, &verboseArg, &outputFilesArg});
|
||||
&indexPosArg, &forceRewriteArg, &backupDirArg, &verboseArg, &outputFilesArg});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <tagparser/abstracttrack.h>
|
||||
#include <tagparser/abstractattachment.h>
|
||||
#include <tagparser/abstractchapter.h>
|
||||
#include <tagparser/backuphelper.h>
|
||||
|
||||
#ifdef TAGEDITOR_JSON_EXPORT
|
||||
# include <reflective_rapidjson/json/reflector.h>
|
||||
|
@ -446,6 +447,11 @@ void setTagInfo(const SetTagInfoArgs &args)
|
|||
fileInfo.setForceIndexPosition(args.forceIndexPosArg.isPresent());
|
||||
fileInfo.setForceRewrite(args.forceRewriteArg.isPresent());
|
||||
|
||||
// set backup path
|
||||
if(args.backupDirArg.isPresent()) {
|
||||
BackupHelper::backupDirectory() = args.backupDirArg.values().front();
|
||||
}
|
||||
|
||||
// iterate through all specified files
|
||||
unsigned int fileIndex = 0;
|
||||
static const string context("setting tags");
|
||||
|
@ -498,14 +504,12 @@ void setTagInfo(const SetTagInfoArgs &args)
|
|||
denotedValues.relevantValues.clear();
|
||||
unsigned int currentFileIndex = 0;
|
||||
for(FieldValue &denotatedValue : denotedValues.allValues) {
|
||||
if(denotatedValue.fileIndex <= fileIndex) {
|
||||
if(relevantDenotedValues.empty() || (denotatedValue.fileIndex >= currentFileIndex)) {
|
||||
if(currentFileIndex != denotatedValue.fileIndex) {
|
||||
currentFileIndex = denotatedValue.fileIndex;
|
||||
relevantDenotedValues.clear();
|
||||
}
|
||||
relevantDenotedValues.push_back(&denotatedValue);
|
||||
if((denotatedValue.fileIndex <= fileIndex) && (relevantDenotedValues.empty() || (denotatedValue.fileIndex >= currentFileIndex))) {
|
||||
if(currentFileIndex != denotatedValue.fileIndex) {
|
||||
currentFileIndex = denotatedValue.fileIndex;
|
||||
relevantDenotedValues.clear();
|
||||
}
|
||||
relevantDenotedValues.push_back(&denotatedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ struct SetTagInfoArgs
|
|||
ApplicationUtilities::Argument forceRewriteArg;
|
||||
ApplicationUtilities::Argument valuesArg;
|
||||
ApplicationUtilities::Argument outputFilesArg;
|
||||
ApplicationUtilities::ConfigValueArgument backupDirArg;
|
||||
ApplicationUtilities::Argument setTagInfoArg;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <c++utilities/conversion/stringconversion.h>
|
||||
#include <c++utilities/io/catchiofailure.h>
|
||||
#include <c++utilities/io/misc.h>
|
||||
#include <c++utilities/io/path.h>
|
||||
#include <c++utilities/tests/testutils.h>
|
||||
|
||||
#include <tagparser/mediafileinfo.h>
|
||||
|
@ -40,6 +41,7 @@ class CliTests : public TestFixture
|
|||
CPPUNIT_TEST(testEncodingOption);
|
||||
CPPUNIT_TEST(testMultipleFiles);
|
||||
CPPUNIT_TEST(testOutputFile);
|
||||
CPPUNIT_TEST(testBackupDir);
|
||||
CPPUNIT_TEST(testMultipleValuesPerField);
|
||||
CPPUNIT_TEST(testHandlingAttachments);
|
||||
CPPUNIT_TEST(testDisplayingInfo);
|
||||
|
@ -63,6 +65,7 @@ public:
|
|||
void testEncodingOption();
|
||||
void testMultipleFiles();
|
||||
void testOutputFile();
|
||||
void testBackupDir();
|
||||
void testMultipleValuesPerField();
|
||||
void testHandlingAttachments();
|
||||
void testDisplayingInfo();
|
||||
|
@ -492,6 +495,34 @@ void CliTests::testOutputFile()
|
|||
remove("/tmp/test1.mkv"), remove("/tmp/test2.mkv");
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests the "--temp-dir /some/path" option of the set operation.
|
||||
*/
|
||||
void CliTests::testBackupDir()
|
||||
{
|
||||
cout << "\nSpecifying a backup/temp dir for set operation" << endl;
|
||||
string stdout, stderr;
|
||||
const string mkvFileName("matroska_wave1/test1.mkv");
|
||||
const auto mkvFile(workingCopyPath(mkvFileName));
|
||||
CPPUNIT_ASSERT(mkvFile.size() >= mkvFileName.size());
|
||||
const auto backupDir(mkvFile.substr(0, mkvFile.size() - mkvFileName.size()));
|
||||
|
||||
const char *const args1[] = {"tageditor", "set", "target-level=30", "title=test1","-f", mkvFile.data(), "--temp-dir", "..", nullptr};
|
||||
TESTUTILS_ASSERT_EXEC(args1);
|
||||
|
||||
// specified output file contains new title
|
||||
const char *const args2[] = {"tageditor", "get", "-f", mkvFile.data(), nullptr};
|
||||
TESTUTILS_ASSERT_EXEC(args2);
|
||||
CPPUNIT_ASSERT(testContainsSubstrings(stdout, {
|
||||
" - \e[1mMatroska tag targeting \"level 30 'track, song, chapter'\"\e[0m\n"
|
||||
" Title test1\n",
|
||||
}));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(0, remove(mkvFile.data()));
|
||||
CPPUNIT_ASSERT_EQUAL(0, remove((backupDir + "test1.mkv").data()));
|
||||
CPPUNIT_ASSERT(remove((mkvFile + ".bak").c_str()));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Tests tagging multiple values per field.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue