-
Notifications
You must be signed in to change notification settings - Fork 38
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
WIP: split the argparser logic to one more level #837
base: master
Are you sure you want to change the base?
Conversation
Currently we have two levels to the factory function to generate the CLI interface for caproto IOCs - ioc_arg_parser -> all-in-one that gives you two dictionaries - template_arg_parser -> gives you a parser and a function to extract those dictionaries The first is useful for reducing boiler plate in servers, the second is useful if you need to inject some additional parameters to be extracted from the CLI. This adds another layer which giver a ArgParser will add all of the standard flags which is useful when you have an existing CLI tool that you want to add caporto features to.
8b91d30
to
cf89ecd
Compare
Can you provide a basic example of how these new features are implemented by a user? How would from caproto.server import PVGroup, ioc_arg_parser, pvproperty, run
class SimpleIOC(PVGroup):
A = pvproperty(value=1, doc="An integer")
B = pvproperty(value=2.0, doc="A float")
C = pvproperty(value=[1, 2, 3], doc="An array of integers (max length 3)")
if __name__ == "__main__":
ioc_options, run_options = ioc_arg_parser(default_prefix="simple:", desc="Example")
ioc = SimpleIOC(**ioc_options)
run(ioc.pvdb, **run_options) |
Adding a log level parameter to the from caproto.server import PVGroup, pvproperty, run
class SimpleIOC(PVGroup):
A = pvproperty(value=1, doc="An integer")
B = pvproperty(value=2.0, doc="A float")
C = pvproperty(value=[1, 2, 3], doc="An array of integers (max length 3)")
if __name__ == "__main__":
ioc = SimpleIOC(prefix="simple")
run(ioc.pvdb, loglevel="info") |
caproto/caproto/ioc_examples/chirp.py Lines 52 to 74 in 46020e4
template_arg_parser .
To use the new one it would be something like ... # other code
parser = ... # where ever you are getting it from now
split_function = extend_arg_parser(parser) # mutates in place!
... # other code
args = parser.parse_args()
... # other code
ioc_options, run_options = split_args(args)
ioc = SimpleIOC(**ioc_options)
run(ioc.pvdb, **run_options) |
I do not think we want to cross the details of setting up loggers and log levels with the business of actually running the IOC. |
Currently we have two levels to the factory function to generate the CLI interface for caproto IOCs
The first is useful for reducing boiler plate in servers, the second is useful if you need to inject some additional parameters to be extracted from the CLI.
This adds another layer which giver a ArgParser will add all of the standard flags which is useful when you have an existing CLI tool that you want to add caporto features to.