Argument
Arguments for inspection based CLI parser.
Argument
Represent argparse arguments.
action: str
property
writable
Get argparse argument action.
choices: List[str]
property
writable
Get argparse argument choices.
default: Any
property
writable
Get argparse argument default.
help: str
property
writable
Get argparse command/argument help message.
metavar: str
property
writable
Get argparse argument metavar.
name: List[str]
property
writable
Get argparse command/argument name.
nargs: Union[int, str]
property
writable
Get argparse argument nargs.
type: Any
property
writable
Get argparse argument type.
__init__(self, docstring, parameters=None)
special
Initialize argparse argument.
Source code in argufy/argument.py
def __init__(
self,
docstring: DocstringParam,
parameters: Optional[inspect.Parameter] = None,
) -> None:
'''Initialize argparse argument.'''
# self.attributes: Dict[Any, Any] = {}
if parameters:
self.default = parameters.default
self.name = parameters # type: ignore
else:
self.default = None
if (
parameters
and parameters.annotation != inspect._empty # type: ignore
):
self.__parse_parameters(parameters)
elif docstring and docstring.type_name:
self.__parse_docstring(docstring)
elif self.default is not None:
self.type = type(self.default)
# if hasattr(self, 'type'):
# self.metavar = (self.type.__name__)
if docstring:
self.help = docstring.description