-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Config command defaults (e.g. from toml or yaml file) #165
Conversation
3cbcd9c
to
677e8d0
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #165 +/- ##
==========================================
- Coverage 96.40% 95.87% -0.54%
==========================================
Files 16 23 +7
Lines 1864 2060 +196
Branches 468 523 +55
==========================================
+ Hits 1797 1975 +178
- Misses 29 43 +14
- Partials 38 42 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Hi Brian - this looks great! Looking through this, a few thoughts:
|
Thanks for looking!
I kinda agree, however there are many ways to interpret
Yes. But again, this is project specific. For example, if we write a CLI tool that lints a repo based on it's
However, some other tools may want to look in some home config directory:
In either case, it's pretty explicit about where the configuration will be coming from.
I 100% agree, but I couldn't think of a better name. Totally open to suggestions! A odd nuance/coincidence is that this hook is VERY similar to |
After a little more time, i have the following thoughts:
|
Agree - I think the simple |
3d6e63b
to
aca7abc
Compare
5899702
to
e6acc02
Compare
db78b86
to
bc2d642
Compare
e89ee32
to
8e0b250
Compare
ba2e304
to
621c250
Compare
9b686c9
to
bca4db5
Compare
This PR aims to make it easier to supply configuration defaults from a configuration file by introducing a new
cyclopts.App
parameter calledbound_args_transform
.bound_args_transform
is a callable (or list of callables) that has signature:The supplied functions should add/modify the provided
bound
object based on some external configuration. Thecommands
parameter are the string CLI commands/subcommands that lead up to the function-to-be-executed. For example,would result in
commands == ("cmd", "subcmd")
Cyclopts has a few builtin transform classes for common situations for yaml, toml, and json. Example usage:
Extending the above example, this would:
bound
object at all.[tool.mytoolname.cmd.subcmd]
and supply the key/value pairs for unset parameters.Other nice parameters of the builtin transforms:
must_exist=False
: whether or not the configuration file must exist.search_parents=False
: iteratively search parenting directories until a config file is found.Resolves #87. @BrendanJM what do you think about the concepts outlined in this post? This branch is not in a functional state yet (and the implementation is not yet ready to be reviewed), but I was wondering if I could get your high level feedback?