docs: Add documentation for new BASH syntax - #6290
Conversation
95d6ad7 to
f72d662
Compare
f72d662 to
c540bd6
Compare
Since snapd 2.77 onward, support for BASH syntax ${VAR:+value}
and ${VAR:-default} is available for environment variable values.
This patch adds it to the documentation, to ensure that it will
be explained in the docs web pages.
c540bd6 to
7d4b681
Compare
mr-cal
left a comment
There was a problem hiding this comment.
Thanks, @sergio-costas !
I've put my suggestion in and am also requesting a review from @canonical/starcraft-authors.
There was a problem hiding this comment.
Pull request overview
Adds documentation to the environment field schema/docs explaining that snapd (>= 2.77) supports Bash parameter expansion in environment variable values, and how to gate usage via assumes.
Changes:
- Document support for
${VAR:+value}and${VAR:-default}in environment variable values (snapd 2.77+). - Clarify limitations (no nested parameter expansion) and provide examples.
- Recommend using
assumes: [snapd2.77]to require the needed snapd feature level.
8537692 to
767d530
Compare
medubelko
left a comment
There was a problem hiding this comment.
Thanks @sergio-costas!
I went deep in trying to make this easier for users to parse. Let me know what you think!
| From snapd 2.77 onward, support for BASH syntax ``${VAR:+value}`` and | ||
| ``${VAR:-default}`` is available for environment variable values. Also | ||
| ``${VAR:+$OTHER_VAR}`` and ``${VAR:-$OTHER_VAR}`` are supported, but internal | ||
| braces are not supported (so , for example, ``${VAR:+${OTHER_VAR}}`` won't work). |
There was a problem hiding this comment.
Here's my attempt to make it a little more digestible:
| From snapd 2.77 onward, support for BASH syntax ``${VAR:+value}`` and | |
| ``${VAR:-default}`` is available for environment variable values. Also | |
| ``${VAR:+$OTHER_VAR}`` and ``${VAR:-$OTHER_VAR}`` are supported, but internal | |
| braces are not supported (so , for example, ``${VAR:+${OTHER_VAR}}`` won't work). | |
| With SnapD 2.77 and higher, this key supports Bash parameter expansions: | |
| - Override the current value with ``${VAR:+override}`` | |
| - Fall back to a value with ``${VAR:-fallback}`` | |
| - Copy another variable's value with ``${VAR:+$OTHER_VAR}`` | |
| - Fall back to another variable's value with ``${VAR:-$OTHER_VAR}`` | |
| Nested braces such as ``${VAR:+${OTHER_VAR}}`` aren't supported. |
There was a problem hiding this comment.
Looks much better, but I still see it a little bit complex... Maybe adding some examples would help?
| To ensure this feature is available, use the ``assumes`` key to require a | ||
| minimum version of snapd, for example ``assumes: [snapd2.77]``. |
There was a problem hiding this comment.
| To ensure this feature is available, use the ``assumes`` key to require a | |
| minimum version of snapd, for example ``assumes: [snapd2.77]``. | |
| For parameter expansion, the ``assumes`` key must be set to a | |
| minimum version of SnapD, such as ``[snapd2.77]``. |
There was a problem hiding this comment.
Maybe... "If parameter expansion is used, it is paramount to set the assumes key to version 2.77 or later (such as assumes: [snapd2.77])".
There was a problem hiding this comment.
I think the word "paramount" feels a little too glittery. I don't like the "such as" in Michael's suggestion either, because it feels a suggestion that you can pin it to whatever version you want, so long as you're pinning it at all.
How about:
| To ensure this feature is available, use the ``assumes`` key to require a | |
| minimum version of snapd, for example ``assumes: [snapd2.77]``. | |
| Since this feature requires a minimum version of SnapD, use the ``assumes`` key to | |
| constrain your snap to a supported SnapD version with ``assumes: [snapd2.77]``. |
Co-authored-by: Michael DuBelko <michael.dubelko@gmail.com> Signed-off-by: Sergio Costas <sergio.costas@canonical.com>
Since snapd 2.77 onward, support for BASH syntax ${VAR:+value} and ${VAR:-default} is available for environment variable values. This patch adds it to the documentation, to ensure that it will be explained in the docs web pages.
make lint && make test.