How to get value from multiple type possibilities #773
-
I have a YAML file which describes languages and toolchains (e.g. GoalGet a version of a toolchain from a YAML file (e.g. python) when the toolchain could look like different types (or have nothing defined). YAML object type possibilitiesPlease note: I would look to the
language: python or language: python
python: 3.6 or language: python
python: "3.6" or language: python
python:
- 3.6
- 2.7 GoalTrying to get the version of python from a list (the first item only), or fall back to getting the value (e.g. My hackIn bash, I could put in a series of defaults. For example, python_version="$(yq eval '.python[0]' .jervis.yml)"
if [ -z "${python_version:-}" -o "${python_version:-}" = null ]; then
python_version="$(yq eval '.python // "2.7"' .jervis.yml)"
fi
echo "Python version found: ${python_version}" The above script is the only way I could figure out how to make it work. Is there a My failed attempt at a one linerPlease note: I tried
But it breaks down so I must be misunderstanding it. I also attempted some type checking but it didn't appear to work the way I thought it would.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Yeah I see - let me take a look I think it's a problem with the |
Beta Was this translation helpful? Give feedback.
Yeah I see - let me take a look I think it's a problem with the
//
operator