-
Notifications
You must be signed in to change notification settings - Fork 55
fix(#507): warn when CLI defaults conflict with TOML #512
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
Changes from 2 commits
49352eb
9684f2e
a51512b
f003676
55db115
ebf479d
aefe569
76b8783
402548b
e0787c7
f42d0b9
19a503e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,6 +303,32 @@ def make_arg_parser( | |
| plugin.add_cli_argument_group(group) | ||
| for action in group._group_actions: | ||
| action.dest = f"plugin.{plugin_id}.{action.dest}" | ||
| if type(action) in { | ||
| argparse._StoreTrueAction, | ||
| argparse._StoreFalseAction, | ||
| }: | ||
| import warnings | ||
|
|
||
| is_store_true = type(action) is argparse._StoreTrueAction | ||
| plugin_name = ( | ||
| action.container.title | ||
| if hasattr(action, "container") | ||
| else str(plugin) | ||
| ) | ||
KyleKing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| text = ( | ||
| f"For {action.option_strings} from {plugin_name}," | ||
| " the default will always override a value configured" | ||
| " in TOML. To resolve, replace `.add_argument(...," | ||
| f' action="store_{str(is_store_true).lower()}")` with' | ||
| f' `(..., action="store_const", const={is_store_true})`' | ||
| ) | ||
KyleKing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| plugin_file, plugin_line = get_source_file_and_line(action) | ||
KyleKing marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| warnings.warn_explicit( | ||
| text, | ||
| UserWarning, | ||
|
||
| filename=plugin_file, | ||
| lineno=plugin_line, | ||
| ) | ||
| return parser | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.