1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
11 def arg(*args, **kwargs):
12 """Decorator for CLI args.
16 >>> @arg("name", help="Name of the new entity")
17 ... def entity_create(args):
21 add_arg(func, *args, **kwargs)
26 def add_arg(func, *args, **kwargs):
27 """Bind CLI arguments to a shell.py `do_foo` function."""
29 if not hasattr(func, 'arguments'):
32 # NOTE(sirp): avoid dups that can occur when the module is shared across
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))