summaryrefslogtreecommitdiff
path: root/cmd2/argparse_custom.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-08-27 13:44:24 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-08-27 13:44:24 -0400
commite650fc3defd7ddeb32eeadeeddccda370539ce1d (patch)
treea4809c8dcdbc3dcf4e1af624ba0e824f0a7c2861 /cmd2/argparse_custom.py
parent5942f2105eb83140a8ab37e655e2561c4d17d3a2 (diff)
parente3a07c59b541b4a0b937c62ef38be6d8c011c0a3 (diff)
downloadcmd2-git-e650fc3defd7ddeb32eeadeeddccda370539ce1d.tar.gz
Merge branch 'master' into 2.0
Diffstat (limited to 'cmd2/argparse_custom.py')
-rw-r--r--cmd2/argparse_custom.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py
index 85b0d903..4e0a9708 100644
--- a/cmd2/argparse_custom.py
+++ b/cmd2/argparse_custom.py
@@ -194,7 +194,7 @@ import re
import sys
# noinspection PyUnresolvedReferences,PyProtectedMember
from argparse import ONE_OR_MORE, ZERO_OR_MORE, ArgumentError, _
-from typing import Callable, Optional, Tuple, Type, Union
+from typing import Any, Callable, Optional, Tuple, Type, Union
from . import ansi, constants
@@ -857,6 +857,24 @@ class Cmd2ArgumentParser(argparse.ArgumentParser):
ansi.style_aware_write(file, message)
+class Cmd2AttributeWrapper:
+ """
+ Wraps a cmd2-specific attribute added to an argparse Namespace.
+ This makes it easy to know which attributes in a Namespace are
+ arguments from a parser and which were added by cmd2.
+ """
+ def __init__(self, attribute: Any):
+ self.__attribute = attribute
+
+ def get(self) -> Any:
+ """Get the value of the attribute"""
+ return self.__attribute
+
+ def set(self, new_val: Any) -> None:
+ """Set the value of the attribute"""
+ self.__attribute = new_val
+
+
# The default ArgumentParser class for a cmd2 app
DEFAULT_ARGUMENT_PARSER = Cmd2ArgumentParser