-
Notifications
You must be signed in to change notification settings - Fork 12
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
extra arguments are not tolerated by the parser, even with Extra.ignore #40
Comments
I'm not sure that strongly coupling the model config of The current workaround for this case is to explicitly add an 'cli_args', 'others' or similar keyword to your Pydantic model. from typing import Optional
from pydantic import BaseModel
from pydantic_cli import run_and_exit
class Options(BaseModel):
alpha: int
beta: float
others: Optional[str]
def example_runner(opts: Options) -> int:
print(f"Mock example running with {opts}")
return 0
if __name__ == "__main__":
run_and_exit(Options, example_runner, description=__doc__, version="0.1.0") Running $> python pydantic_cli_with_extras.py --alpha 1 --beta 1 --others '--pass-through-options 1234 a=1 b=2'
Mock example running with alpha=1 beta=1.0 others='--pass-through-options 1234 a=1 b=2' |
Consider the situation where the user cannot modify the arguments passed in the terminal. Also, by default, |
I think that pydantic's default of Also, pydantic_cli doesn't uses any of the core config values |
Ok, thank you for your help. Fell free to reject the associated PR and close this issue if you have no plans on adding an option to ignore extra arguments. I will most likely fork the project to fit my personal needs. |
I don't think that using However, adding a new key to the config of https://github.com/mpkocher/pydantic-cli/blob/master/pydantic_cli/core.py |
@lpasselin Adding a PR that is very similar to one you closed but leveraging Please add an inline docs to the DefaultConfig in core.py and add a new test and we should be good to go. Thanks for the feedback and comments. |
The parser raises an error when extra arguments are provided.
It could be useful to only parse known args.
For example, if
MyPydanticModel.Config.extra == pydantic.Extra.ignore
, useparser.parse_known_args()
to tolerate extra arguments.The text was updated successfully, but these errors were encountered: