Upload the contribution of vstf as bottleneck network framework.
[bottlenecks.git] / vstf / vstf / common / cliutil.py
1 def arg(*args, **kwargs):
2     """Decorator for CLI args.
3
4     Example:
5
6     >>> @arg("name", help="Name of the new entity")
7     ... def entity_create(args):
8     ...     pass
9     """
10     def _decorator(func):
11         add_arg(func, *args, **kwargs)
12         return func
13     return _decorator
14
15
16 def add_arg(func, *args, **kwargs):
17     """Bind CLI arguments to a shell.py `do_foo` function."""
18
19     if not hasattr(func, 'arguments'):
20         func.arguments = []
21
22     # NOTE(sirp): avoid dups that can occur when the module is shared across
23     # tests.
24     if (args, kwargs) not in func.arguments:
25         # Because of the semantics of decorator composition if we just append
26         # to the options list positional options will appear to be backwards.
27         func.arguments.insert(0, (args, kwargs))