Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / common / cliutil.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10
11 def arg(*args, **kwargs):
12     """Decorator for CLI args.
13
14     Example:
15
16     >>> @arg("name", help="Name of the new entity")
17     ... def entity_create(args):
18     ...     pass
19     """
20     def _decorator(func):
21         add_arg(func, *args, **kwargs)
22         return func
23     return _decorator
24
25
26 def add_arg(func, *args, **kwargs):
27     """Bind CLI arguments to a shell.py `do_foo` function."""
28
29     if not hasattr(func, 'arguments'):
30         func.arguments = []
31
32     # NOTE(sirp): avoid dups that can occur when the module is shared across
33     # tests.
34     if (args, kwargs) not in func.arguments:
35         # Because of the semantics of decorator composition if we just append
36         # to the options list positional options will appear to be backwards.
37         func.arguments.insert(0, (args, kwargs))