Skip to content

CLI: Add netrc formatted option to show command. - #13387

Open
Millak wants to merge 4 commits into
keepassxreboot:developfrom
Millak:add-netrc-show-option
Open

CLI: Add netrc formatted option to show command.#13387
Millak wants to merge 4 commits into
keepassxreboot:developfrom
Millak:add-netrc-show-option

Conversation

@Millak

@Millak Millak commented May 28, 2026

Copy link
Copy Markdown

Fixes #13380

Testing strategy

Added tests to the TestCli::testShow() test case.

Type of change

  • ✅ New feature (change that adds functionality)

This follows some comments on #13381 which pointed out that it's exposing the entire database for the one line that's needed, so it'd be better to be an option in 'show'. Also because it's meant to be ephemeral, not a full dump of all the data.

@droidmonkey droidmonkey added feature: CLI pr: new feature Pull request adds a new feature labels Jun 4, 2026
@droidmonkey droidmonkey added this to the v2.8.0 milestone Jun 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new keepassxc-cli show --format-netrc option to emit a .netrc-style representation of a single entry (URL/username/password), intended as an ephemeral alternative to exporting the entire database.

Changes:

  • Added --format-netrc option to the show command and adjusted output behavior to suppress attachments/TOTP output in netrc mode.
  • Implemented .netrc-style field naming (machine, login, password) when netrc mode is enabled.
  • Extended TestCli::testShow() with coverage asserting stable netrc output even when other show options are also provided.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/cli/Show.h Declares the new --format-netrc CLI option.
src/cli/Show.cpp Implements netrc-mode output and interaction with existing show options.
tests/TestCli.cpp Adds tests validating the new netrc output behavior.

Comment thread src/cli/Show.cpp Outdated
Comment thread src/cli/Show.cpp Outdated
Comment thread tests/TestCli.cpp Outdated
Comment thread src/cli/Show.cpp
Comment thread src/cli/Show.cpp Outdated
@droidmonkey
droidmonkey force-pushed the add-netrc-show-option branch from bba073b to 106d756 Compare June 7, 2026 15:07
Comment thread src/cli/Show.cpp Outdated

// First we do the special case for showNetrc.
if (showNetrcFormat) {
const QString entryUrl = entry->resolveMultiplePlaceholders(entry->attributes()->value(EntryAttributes::URLKey));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I broke this out so I could parse it to get just the UrlHost but I wasn't able to get the code working for it. I see PlaceholderType::UrlHost in src/core/Entry.h and I saw UrlFormattingOption in qurl.h (in Qt) but I wasn't able to get either one to work for me.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/cli/Show.cpp
Comment on lines 71 to 75
bool showTotp = parser->isSet(Show::TotpOption);
bool showProtectedAttributes = parser->isSet(Show::ProtectedAttributesOption);
bool showAllAttributes = parser->isSet(Show::AllAttributesOption);
bool showNetrcFormat = parser->isSet(Show::NetrcOption);
QStringList attributes = parser->values(Show::AttributesOption);
Comment thread src/cli/Show.cpp
Comment on lines +117 to +123
const QString entryUrl =
entry->resolveMultiplePlaceholders(entry->attributes()->value(EntryAttributes::URLKey));
if (entryUrl.isEmpty()) {
out << QString("default ");
} else {
out << QString("machine ") << entryUrl << QString(" ");
}
Comment thread tests/TestCli.cpp
Comment on lines +2211 to +2213
QByteArray expectedNetrcOutput = QByteArray("machine http://www.somesite.com/ "
"login \"User Name\" "
"password \"Password\"\n");
Comment thread src/cli/Show.cpp
Comment on lines +117 to +118
const QString entryUrl =
entry->resolveMultiplePlaceholders(entry->attributes()->value(EntryAttributes::URLKey));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will want to put this into a QUrl::fromUserInput then QUrl::toDisplayString with the options

QUrl::RemoveAuthority | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash

Or force a construction using the schema + host

@droidmonkey droidmonkey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: CLI pr: new feature Pull request adds a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add netrc export option

3 participants