def __call__(self, parser, namespace, flag, unused_option_string=None): """Sets the `self.dest` attribute in `namespace` to the parsed value of `flag`. If `flag` parses to a boolean True value then the attribute value is 'download'. If `flag` parses to a boolean False value then the attribute value is ``None``. Otherwise the attribute value is the value of `flag`. Args: parser (str): Argument parser object this group belongs to. namespace (object): Namespace to receive parsed value via setattr. flag (str): Value parsed from the command line. """ try: flag_as_bool = util.parse_bool(flag, additional_true=['download']) except TypeError: if util.is_url(flag): value = flag else: value = os.path.abspath(os.path.expanduser(flag)) if not (os.path.isdir(value) or util.file_accessible(value)): raise argparse.ArgumentError(self, "Boolean, 'download', valid path, or URL required: %s" % value) else: if flag_as_bool == True: value = 'download' elif flag_as_bool == False: value = None setattr(namespace, self.dest, value)
def __call__(self, parser, namespace, flag, unused_option_string=None): """Sets the `self.dest` attribute in `namespace` to the parsed value of `flag`. If `flag` parses to a boolean via :any:`tau.util.parse_bool` then the attribute value is that boolean value. Args: parser (str): Argument parser object this group belongs to. namespace (object): Namespace to receive parsed value via setattr. flag (str): Value parsed from the command line/ """ try: setattr(namespace, self.dest, util.parse_bool(flag)) except TypeError: raise argparse.ArgumentError(self, 'Boolean value required')