-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write CLI diagnostic messages to stderr #2103
Write CLI diagnostic messages to stderr #2103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using qInfo
? https://doc.qt.io/qt-5/qtglobal.html#qInfo
Reading the doc you provided, I get the feeling this function is more meant for debugging purposes. But now that you mention it, I see that I used QTextStream for stderr to stay consistent with the QTextStream used for stdout and stdin. |
If we want to be meticulous we should use |
What gets actually printed to the screen also depends on your system's Qt debugging settings. |
becad33
to
9354c5b
Compare
OK, so we merged the new CLI STDIN/STDOUT/STDERR changes that @phoerious made. This directly conflicts with this entire PR. Can you please look at the new architecture and update your PR to fit? I think it would be wise to redirect to STDERR only if a flag is set (ie, change the STDOUT to STDERR if --stderr flag is set). That way we can have the best of both worlds. Script friendly and user friendly. |
I can make the changes, however I fail to see how using stdout by default is more user friendly. When an user is using the shell interactively, all messages from stderr are displayed on the terminal. And as I mentioned above only the actual result of a command is supposed to be output to stdout. |
That is fine, I agree with you. |
I don't think everything should go to stderr directly if it's not an error or a warning. A command that has output which may be piped must at least have an option for this behaviour (although I think that should rather be suppressing everything else), but just printing all diagnostics to stderr is probably not advisable. Various tools use stderr to detect errors in script execution (apart from checking the return value, which on its own may be misleading) and highlight stderr output differently from stout. Suppressing diagnostics may also be in implicit option where the process checks if the target is a tty or not. If not, any non-result output is suppressed and password prompts should go to stderr, or course. Errors and warnings always go to stderr. |
Writing the prompt to stderr greatly helps with the use of keepassxc-cli in automated scripts or as a password provider for programs like mutt or borg. This is done in accordance with POSIX that specifies that diagnostic messages be sent to stderr. This commit should be a first step in solving the following issues: keepassxreboot#831, keepassxreboot#1221
As mentioned in 1dce5b0, POSIX specifies that all diagnostic and error messages are to be sent to stderr, only meaningful data shall be output to stdout (for example: attributes retrieved via keepassxc-cli show). Stream variables were renamed using the <stream>TextStream convention for consistency's sake. It should be noted that stderr is supposed to be unbuffered, some calls to flush() might not be useful anymore.
9354c5b
to
f6b88cd
Compare
I didn't realize that the CLI tests were hidden with the GUI ones ^^ |
The CLI tests depend on some GUI routines for clipboard actions, so they need am X server to execute. |
Description
All of the diagnostic and status messages in keepassxc-cli are now output to stderr instead of stdout.
Only meaningful data (data that might be piped to another process) like generated passwords or attributes retrieved with show is sent to stdout.
Motivation and context
Writing the prompt to stderr greatly helps with the use of keepassxc-cli in automated scripts or as a password provider for programs like mutt or borg.
This is done in accordance with POSIX that specifies that diagnostic messages be sent to stderr.
This commit should be a first step in solving the following issues: #831, #1221
How has this been tested?
Before the change, even the prompt goes to stdout:
After the change, only the attributes are sent to stdout:
To confirm I tried to use the new version to unlock a borg repo and it worked without any problems:
Types of changes
Checklist:
-DWITH_ASAN=ON
. [REQUIRED]