Explorar o código

added possibility to update choices

Dimitri Korsch %!s(int64=3) %!d(string=hai) anos
pai
achega
456904ad6b
Modificáronse 1 ficheiros con 11 adicións e 0 borrados
  1. 11 0
      cvargparse/parser/base.py

+ 11 - 0
cvargparse/parser/base.py

@@ -80,6 +80,17 @@ class BaseParser(LoggerMixin, argparse.ArgumentParser):
 
 		self.add_args(arglist)
 
+	def add_choices(self, dest, *choices):
+		for action in self._actions:
+			if action.dest == dest:
+				assert action.choices is not None, \
+					f"{action} has no choices!"
+
+				action.choices.extend(choices)
+				break
+		else:
+			raise ValueError("Argument with destination \"{dest}\" was not found!")
+
 
 	@property
 	def args(self):