Browse Source

added some convenience class methods

Dimitri Korsch 3 years ago
parent
commit
03497c1563
1 changed files with 14 additions and 0 deletions
  1. 14 0
      cvargparse/argument.py

+ 14 - 0
cvargparse/argument.py

@@ -5,6 +5,20 @@ class Argument(object):
 		self.args = args # positional arugments
 		self.kw = kw # keyword arguments
 
+	@classmethod
+	def int(cls, *args, **kw):
+		arg_type = kw.pop("type", int)
+		return cls(*args, type=arg_type, **kw)
+
+	@classmethod
+	def float(cls, *args, **kw):
+		arg_type = kw.pop("type", float)
+		return cls(*args, type=arg_type, **kw)
+
+	@classmethod
+	def flag(cls, *args, **kw):
+		action = kw.pop("action", "store_true")
+		return cls(*args, action=action, **kw)
 
 class FileArgument(Argument):
 	def __init__(self, *args, **kw):