glomatico / gamdl

A Python CLI app for downloading Apple Music songs/music videos/posts.
587 stars 76 forks source link

Added support for configuration from ENV #86

Closed Cronocide closed 3 months ago

Cronocide commented 3 months ago

Thank you so much for your work on this project! I love it and use it every day.

In an effort to make execution in a docker container simpler and easier, I've added support for configuration via environment variables that can be set by a container orchestrator often more conveniently than command-line options can be set. My current docker container for this app hacks environment support on top of the current release, but I thought adding it to the source would be cleaner, and make it simpler to define a dockerfile for.

I'd love to go ahead and define a Docker container for this project as well, but I wanted to offer this change up first to get your feedback before I start on the dockerfile.

Cronocide commented 3 months ago

If the environment variables are evaluated in no_config_callback and not in the Click context then type enforcement is lost and need to be manually checked and inserted into the Click context. Is this what you'd prefer to the Click defaults? For reference the lambdas are what the Click docs recommend. I tried using Click's envvar kwarg, but learned that it isn't supported for this mix of arguments and options.

glomatico commented 3 months ago

Can't you use the type_cast_value function for casting the environment values?https://github.com/Cronocide/gamdl/blob/733a4bb2c61d9ce06dd186a65ab6c33178aaeb43/gamdl/cli.py#L43

Cronocide commented 3 months ago

Like this? Env variables can configure the script in conjunction with a config file or CLI parameters.

glomatico commented 3 months ago

Yes 👍 that should do the job