-
-
Notifications
You must be signed in to change notification settings - Fork 95
CLI Serialization Fixes #649
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
Conversation
kschwab
commented
Jul 2, 2025
- Adds serialization of sub commands.
- Fixes serialization of kebab case of flags.
Thanks @kschwab Is it a fix for an issue? |
@hramezani yes, it is an issue I found locally. I can open a formal ticket if you would like.
from pydantic_settings import BaseSettings, CliApp
class Cfg(BaseSettings, cli_kebab_case=True):
foo_kebab: int = 123
args = CliApp.serialize(Cfg())
print(args)
#> ['--foo_kebab', '123']
CliApp.run(Cfg, cli_args=args)
"""
usage: example.py [-h] [--foo-kebab int]
example.py: error: unrecognized arguments: --foo_kebab 123
""" With this fix, it will correctly apply the kebab case to serialization: from pydantic_settings import BaseSettings, CliApp
class Cfg(BaseSettings, cli_kebab_case=True):
foo_kebab: int = 123
print(CliApp.serialize(Cfg()))
#> ['--foo-kebab', '123']
print(CliApp.run(Cfg, cli_args=args))
#> foo_kebab=123 I also missed serialization of subcommands, which addressed as well in this PR. See added test. |
I also just noticed that |
This reverts commit 9380bc6.
fa35ea9
to
e985e22
Compare
Ok @hramezani, this is ready for review again. When I looked closer, there were a handful of bugs I found with the original serialization. The change set looks larger then it is. I reverted the original serialization implementation, and consolidated it into two standalone functions. The bugs I found and fixed were:
All the newly added tests currently fail on main. |
Thanks @kschwab, Great job! |