Skip to content

Commit

Permalink
add flag and option functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hwikle-lanl committed Feb 26, 2024
1 parent 0366274 commit 364e98c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/pavilion/expression_functions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,28 @@ def num(val):
raise RuntimeError("Invalid value '{}' given to num.".format(val))


def flag(val: str, flag_str: str) -> str:
"""Return a flag string for a boolean variable, if
the variable is set, or an empty string otherwise."""

if val.lower() in {'true', 'on', 'yes'}:
return flag_str
elif val.lower() in {'false', 'off', 'no'}:
return ''
else:
raise ValueError(f'Could not convert {val} into boolean-like.')


def option(val: str, option_str: str) -> str:
"""Return an option string for a boolean variable, if
it has a non-null value, or an empty string otherwise."""

if val.lower() in {'null', 'none'}:
return ''
else:
return f"{option_str}='{val}'"


class FunctionPlugin(IPlugin.IPlugin):
"""Plugin base class for math functions.
Expand Down

0 comments on commit 364e98c

Please sign in to comment.