summaryrefslogtreecommitdiffstats
path: root/openstack/common/processutils.py
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2012-11-23 15:50:04 +0000
committerMark McLoughlin <markmc@redhat.com>2012-11-29 17:40:44 +0000
commitd194fd9edc2f94ffb3a922a853a7c4421fe44109 (patch)
tree66e0157a83a1697a8f934bed11ee320fea9b6e30 /openstack/common/processutils.py
parent21e1cd3c01675c2df38f2833ca1ca8edb6d399d1 (diff)
downloadoslo-d194fd9edc2f94ffb3a922a853a7c4421fe44109.tar.gz
oslo-d194fd9edc2f94ffb3a922a853a7c4421fe44109.tar.xz
oslo-d194fd9edc2f94ffb3a922a853a7c4421fe44109.zip
Improve cfg's argparse sub-parsers support
In order for sub-parsers to be useful, you need some way of knowing which sub-parser was chosen during argument parsing. It's pretty obvious from the current sub-parsers test case that we don't have a convenient interface for this. One way of doing it is to use the 'dest' argument when adding sub-parsers: >>> subparsers = parser.add_subparsers(dest='cmd') >>> subparsers.add_parser('a') >>> subparsers.add_parser('b') >>> parser.parse_args(['a']) Namespace(cmd='a') The most sensible way to map this into cfg concepts is to register sub-parsers as an Opt. This way, we can make name and argument values of the sub-parser as an attribute on the ConfigOpts object: >>> def add_parsers(subparsers): ... a = subparsers.add_parser('a') ... a.add_argument('id') ... b = subparsers.add_parser('b') ... >>> CONF.register_cli_opt(SubCommandOpt('cmd', handler=add_parsers)) True >>> CONF(['a', '10']) >>> CONF.cmd.name, CONF.cmd.id ('a', '10') The handler method is a bit awkward, but each time cfg is to parse command line args it takes all the registered opts and creates a new argparse parser. So we need to be able to re-add the sub-parsers each time. Change-Id: I01bfd01bf8853cf57a9248b1663eb3da142366a4
Diffstat (limited to 'openstack/common/processutils.py')
0 files changed, 0 insertions, 0 deletions