Skip to content

feat: Route --version output to stdout #1431

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

neo-anderson
Copy link

@neo-anderson neo-anderson commented Apr 5, 2025

Currently, saml2aws --version prints the application version to stderr. This change modifies the behavior to print the version string to stdout instead while other logs and errors remain on stderr.

Reasoning:

Printing the version to stdout aligns better with common scripting practices and standard CLI tool behavior for version reporting. This makes it easier to capture the version string programmatically without needing stderr redirection (2>&1).

For example, users with bootstrapping or environment setup scripts that check dependency versions currently need to add special handling for saml2aws like

version = result.stdout.strip() if tool != "saml2aws" else result.stderr.strip()

or like

VERSION=$(saml2aws --version 2>&1)

Routing --version output to stdout removes this inconsistency.

#1432

@codecov-commenter
Copy link

codecov-commenter commented Apr 23, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 28.14%. Comparing base (99d6fe4) to head (6e86cdc).
Report is 155 commits behind head on master.

Files with missing lines Patch % Lines
cmd/saml2aws/main.go 0.00% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1431       +/-   ##
===========================================
- Coverage   42.19%   28.14%   -14.06%     
===========================================
  Files          54       70       +16     
  Lines        6456    12540     +6084     
===========================================
+ Hits         2724     3529      +805     
- Misses       3283     8535     +5252     
- Partials      449      476       +27     
Flag Coverage Δ
unittests 28.14% <0.00%> (-14.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RossRichardson RossRichardson self-requested a review April 23, 2025 02:26
Copy link

@RossRichardson RossRichardson left a comment

Choose a reason for hiding this comment

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

Instead of reimplementing the Version() function it looks like we can set the usage and version output to write with os.stdout using .UsageWriter().

So we keep the .Version( and we set the .UsageWriter(. I've checked, but we should verify, this should not interfere with error messages caused by incorrect commands from going to stderr because that is handled by fatalUsage().

https://github.com/alecthomas/kingpin/blob/64d23c54e3e2a385ce12757939bed9c632d1693c/app.go#L146

@neo-anderson
Copy link
Author

Instead of reimplementing the Version() function it looks like we can set the usage and version output to write with os.stdout using .UsageWriter().

So we keep the .Version( and we set the .UsageWriter(. I've checked, but we should verify, this should not interfere with error messages caused by incorrect commands from going to stderr because that is handled by fatalUsage().

https://github.com/alecthomas/kingpin/blob/64d23c54e3e2a385ce12757939bed9c632d1693c/app.go#L146

Thanks for the review. That's way cleaner.

@neo-anderson
Copy link
Author

I verified that errors are sent to stderr by running this: $GOPATH/bin/saml2aws invalid 1>out.txt 2>err.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants