Skip to content

feat: support env var as default flag value #75

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 3 commits into
base: main
Choose a base branch
from
Open

Conversation

molisani
Copy link
Member

@molisani molisani commented Apr 1, 2025

Resolves #62

Describe your changes
Expose functionality for application developers to pull the default value for a flag from an environment variable. This was already possible manually, but integrating it as a first-class feature allows for better formatting of error messages and the ability to "redact" the value in Stricli-generated output (for secrets).

Testing performed
Added several new test cases and updated the formatting baselines to achieve complete coverage.

Additional context
One side-effect is that CommandContext["process"] is now StricliProcess rather than just WritableStreams to allow env to be defined. The differences between the two types are just optional properties so there shouldn't be any issues.

@molisani molisani added the enhancement ✨ New feature or request label Apr 1, 2025
@molisani molisani self-assigned this Apr 1, 2025
@molisani molisani requested a review from a team as a code owner April 1, 2025 16:48
@github-actions github-actions bot added core ⚙ Relates to the @stricli/core package documentation 📝 Improvements or additions to documentation labels Apr 1, 2025
// THEN
compareToBaseline(this, StringArrayBaselineFormat, lines);
});

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we also add a redact: true test?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah good catch, didn't have a case for redact in the formatting baselines.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh at the moment there isn't any difference in the help text when redact: true is enabled. Should there be?

    [--requiredBoolean/--noRequiredBoolean]  required boolean flag           [default = <from env REQUIRED_BOOLEAN>]
 -h --help                                   Print help information and exit

Copy link
Member Author

Choose a reason for hiding this comment

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

At the moment the help text doesn't display the value of the environment variable, only the name. While I think it would be incredibly handy to print the value (or redacted value) we also still need to print the name and all of that takes up a lot of space. Not sure what the best display would be yet.

molisani and others added 3 commits April 9, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core ⚙ Relates to the @stricli/core package documentation 📝 Improvements or additions to documentation enhancement ✨ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First-class support for using env variables as flag defaults
2 participants