mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-08-18 03:00:50 -04:00
Add a -n (--notes) option to keepassxc-cli add
and edit
commands
This commit is contained in:
parent
8a4a804c8c
commit
55eb855267
5 changed files with 47 additions and 1 deletions
|
@ -36,6 +36,11 @@ const QCommandLineOption Add::UsernameOption = QCommandLineOption(QStringList()
|
|||
const QCommandLineOption Add::UrlOption =
|
||||
QCommandLineOption(QStringList() << "url", QObject::tr("URL for the entry."), QObject::tr("URL"));
|
||||
|
||||
const QCommandLineOption Add::NotesOption = QCommandLineOption(QStringList() << "n"
|
||||
<< "notes",
|
||||
QObject::tr("Notes for the entry."),
|
||||
QObject::tr("Notes"));
|
||||
|
||||
const QCommandLineOption Add::PasswordPromptOption =
|
||||
QCommandLineOption(QStringList() << "p"
|
||||
<< "password-prompt",
|
||||
|
@ -51,6 +56,7 @@ Add::Add()
|
|||
description = QObject::tr("Add a new entry to a database.");
|
||||
options.append(Add::UsernameOption);
|
||||
options.append(Add::UrlOption);
|
||||
options.append(Add::NotesOption);
|
||||
options.append(Add::PasswordPromptOption);
|
||||
positionalArguments.append({QString("entry"), QObject::tr("Path of the entry to add."), QString("")});
|
||||
|
||||
|
@ -105,6 +111,10 @@ int Add::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<Q
|
|||
entry->setUrl(parser->value(Add::UrlOption));
|
||||
}
|
||||
|
||||
if (!parser->value(Add::NotesOption).isEmpty()) {
|
||||
entry->setNotes(parser->value(Add::NotesOption).replace("\\n", "\n"));
|
||||
}
|
||||
|
||||
if (parser->isSet(Add::PasswordPromptOption)) {
|
||||
if (!parser->isSet(Command::QuietOption)) {
|
||||
out << QObject::tr("Enter password for new entry: ") << flush;
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
|
||||
static const QCommandLineOption UsernameOption;
|
||||
static const QCommandLineOption UrlOption;
|
||||
static const QCommandLineOption NotesOption;
|
||||
static const QCommandLineOption PasswordPromptOption;
|
||||
static const QCommandLineOption GenerateOption;
|
||||
static const QCommandLineOption PasswordLengthOption;
|
||||
|
|
|
@ -41,6 +41,7 @@ Edit::Edit()
|
|||
// Using some of the options from the Add command since they are the same.
|
||||
options.append(Add::UsernameOption);
|
||||
options.append(Add::UrlOption);
|
||||
options.append(Add::NotesOption);
|
||||
options.append(Add::PasswordPromptOption);
|
||||
options.append(Edit::TitleOption);
|
||||
positionalArguments.append({QString("entry"), QObject::tr("Path of the entry to edit."), QString("")});
|
||||
|
@ -91,9 +92,10 @@ int Edit::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<
|
|||
|
||||
QString username = parser->value(Add::UsernameOption);
|
||||
QString url = parser->value(Add::UrlOption);
|
||||
QString notes = parser->value(Add::NotesOption);
|
||||
QString title = parser->value(Edit::TitleOption);
|
||||
bool prompt = parser->isSet(Add::PasswordPromptOption);
|
||||
if (username.isEmpty() && url.isEmpty() && title.isEmpty() && !prompt && !generate) {
|
||||
if (username.isEmpty() && url.isEmpty() && notes.isEmpty() && title.isEmpty() && !prompt && !generate) {
|
||||
err << QObject::tr("Not changing any field for entry %1.").arg(entryPath) << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -108,6 +110,10 @@ int Edit::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer<
|
|||
entry->setUsername(username);
|
||||
}
|
||||
|
||||
if (!notes.isEmpty()) {
|
||||
entry->setNotes(notes.replace("\\n", "\n"));
|
||||
}
|
||||
|
||||
if (!url.isEmpty()) {
|
||||
entry->setUrl(url);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue