Skip to content
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

Option parsing from environment variables #4

Open
KyleLeneau opened this issue Feb 28, 2020 · 9 comments
Open

Option parsing from environment variables #4

KyleLeneau opened this issue Feb 28, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@KyleLeneau
Copy link

It would be super nice/helpful to parse an options value from an Environment variable value as well taking what is passed in the command line call as the priority over the ENV variable. For CLI's that run in CI or automated environments this is super helpful as it would allow not having to print the value in the ENV variable and could keep it hidden. Not only that but it would be very convenient for repeated uses on commands!

import ArgumentParser

struct MyCommand: ParsableCommand {
    @Option(name: .shortAndLong, help: "The API Secret.", env: "SERVICE_API_SECRET")
    var secret: String
}

Usage:
mycommand --secret QWERTY12345
or
mycommand (where SERVICE_API_SECRET='QWERTY12345'

@danieleggert
Copy link

Yes. We have been working on this already, and we’ll open a PR within the next week or two. There are still a lot of open questions about how to do this right, and we’d love to get feedback from everyone.

@KyleLeneau
Copy link
Author

Awesome, I am happy to provide some feedback on a PR!

@natecook1000 natecook1000 added the enhancement New feature or request label Feb 29, 2020
@KyleLeneau
Copy link
Author

@danieleggert Any update on the progress of this?

@danieleggert danieleggert mentioned this issue Apr 5, 2020
7 tasks
@danieleggert
Copy link

@danieleggert Any update on the progress of this?

Please check out #109 — it’s almost done.

@griffin-stewie
Copy link
Contributor

any updates?

@kojirou1994
Copy link

still waiting😭

@philprime
Copy link

I this still on the roadmap?

@rauhul rauhul added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Feb 20, 2022
@fkorotkov
Copy link

@rauhul, do you have a preference on @KyleLeneau's proposal in this issue vs @danieleggert implementation in #109 vs something new like auto-magically populate values based on command names and argument names. For example, if we have a root command tart and sub-command push with a --populate-cache flag then set it automatically to a value of TART_PUSH_POPULATE_CACHE if defined?

@rauhul
Copy link
Contributor

rauhul commented Feb 20, 2024

I was thinking about a different approach where the parsing pipeline is composed of ArgumentValueProviders, the command line would be one such provider. I haven't fleshed out the idea but the benefit is that users could add their own argument providers depending on their use cases.

e.g. we could provide support out of the box for json config files, environment, .env files, NSUserDefaults, etc...

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

No branches or pull requests

8 participants