Skip to content
Snippets Groups Projects
Commit c91b6aeb authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

ENH: allow default variable in get_variable

parent 480bd941
No related branches found
No related tags found
No related merge requests found
...@@ -54,17 +54,20 @@ class FileTree(object): ...@@ -54,17 +54,20 @@ class FileTree(object):
res.update(self.variables) res.update(self.variables)
return res return res
def get_variable(self, name: str) -> str: def get_variable(self, name: str, default=None) -> str:
""" """
Gets a variable used to fill out the template Gets a variable used to fill out the template
:param name: variable name :param name: variable name
:param default: default variables (if not set an error is raised for a missing variable)
:return: value of the variable :return: value of the variable
""" """
variables = self.all_variables variables = self.all_variables
if name in variables: if name in variables and variables[name] is not None:
return variables[name] return variables[name]
raise MissingVariable('Variable {} not found in sub-tree or parents'.format(name)) if default is None:
raise MissingVariable('Variable {} not found in sub-tree or parents'.format(name))
return default
def _get_template_tree(self, short_name: str) -> Tuple["FileTree", str]: def _get_template_tree(self, short_name: str) -> Tuple["FileTree", str]:
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment