File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -956,6 +956,9 @@ def parse_additional_flags(
956
956
:return: A DockerRunFlags object that will return new objects if respective parameters were None and
957
957
additional flags contained a flag for that object or the same which are passed otherwise.
958
958
"""
959
+ # Argparse refactoring opportunity: custom argparse actions can be used to modularize parsing (e.g., key=value)
960
+ # https://docs.python.org/3/library/argparse.html#action
961
+
959
962
# Configure parser
960
963
parser = NoExitArgumentParser (description = "Docker run flags parser" )
961
964
parser .add_argument (
Original file line number Diff line number Diff line change 5
5
LOG = logging .getLogger (__name__ )
6
6
7
7
8
- # Implements the `exit_on_error=False` behavior introduced in Python 3.9 to support older Python versions
9
- # and prevents further SystemExit for other error categories.
10
- # Limitations of error cases: https://stackoverflow.com/a/67891066/6875981
11
- # Subclassing workaround example: https://stackoverflow.com/a/59072378/6875981
12
8
class NoExitArgumentParser (argparse .ArgumentParser ):
9
+ """Implements the `exit_on_error=False` behavior introduced in Python 3.9 to support older Python versions
10
+ and prevents further SystemExit for other error categories.
11
+ * Limitations of error categories: https://stackoverflow.com/a/67891066/6875981
12
+ * ArgumentParser subclassing example: https://stackoverflow.com/a/59072378/6875981
13
+ """
14
+
13
15
def exit (self , status : int = ..., message : Optional [str ] = ...) -> NoReturn :
14
16
LOG .warning (f"Error in argument parser but preventing exit: { message } " )
15
17
Original file line number Diff line number Diff line change @@ -168,6 +168,9 @@ def test_labels(self):
168
168
argument_string = r'--label ""' # assert that we gracefully handle invalid labels
169
169
flags = Util .parse_additional_flags (argument_string )
170
170
assert flags .labels == {}
171
+ argument_string = r"--label =bar" # assert that we ignore empty labels
172
+ flags = Util .parse_additional_flags (argument_string )
173
+ assert flags .labels == {}
171
174
172
175
def test_network (self ):
173
176
argument_string = r'-v "/tmp/test.jar:/tmp/foo bar/test.jar" --network mynet123'
You can’t perform that action at this time.
0 commit comments