Hejsil / zig-clap

Command line argument parsing library
MIT License
939 stars 67 forks source link

Add support for environment variables #121

Closed fkollmann closed 7 months ago

fkollmann commented 7 months ago

Please add support for environment variables, when specified as upper-case names without any '-' or '--' prefix.

Example:

\\-w, --worker-count <usize>, WORKER_COUNT   Specifies the amount of worker threads to use. Defaults to 4.

The name of the environment variable is WORKER_COUNT.

When running micro services within our k8s infrastructure, we usually provide arguments using environment variables.

Hejsil commented 7 months ago

I don't really think this belongs in clap itself. There are endless niche ways one might want to provide default values. clap answer to that is to just let the programmer create that themselfs. Anything from res.args.@"worker-count" orelse 4 to res.args.@"worker-count" orelse { <complicated logic goes here> }.

I suggest just creating a function that gets an enviorment variable and parses it as an int. Then do res.args.@"worker-count" orelse intEnv("WORKER_COUNT") orelse 4 or whatever you come up with.