-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide tree heading when cmd has no stdout/stderr #11
Comments
It'd be tough from the One thing you can do is use the commands:
unpushed: |
branches=$(get unpushed branches output)
if test -n "$branches"
then
echo "# ${TREE_NAME}"
echo "$branches"
fi |
Thanks! That got me pointed me in the right direction: if test -n "$(git unpushed)"; then
echo "# ${TREE_NAME}"
echo " $(git unpushed --color=always)"
fi One thing I noticed is that trying to use a variable didn't work because
won't work because |
Indeed -- there is a syntax clash between the shellexpand syntax we use for expansions and the I'm not 100% sure whether this should be considered a bug although it could be better. There is a supported way to do it currently, though. The current method to make this work is to use Double- This does mean that the convention PID shell variable If this is not good enough, what could we do instead? Option (X): Alternatives to this current behavior would be to change shellexpand so that we can specify the expansion syntax, eg. maybe we could use a handlebars-like Option (Y): Another alternative would be that we could change shellexpand so that it ignores the bare I'd like to hear your thoughts on whether Option (Y) is worth exploring. It's slightly contingent on the upstream shellexpand project accepting an option to disable the bare That said, even if we changed shellexpand then the syntax clash would still exist because Is another Option (Z) alternative to leave undefined variables as-is and not expand them? I believe we currently expand them to empty strings, akin to what a shell does. Evaluating to an empty string has some advantages because it ensures that there's no ambiguity between garden variables and shell variables. The simple answer is, "shell variables require escaping", but I'm not sure if that's too rigid of a stance. Option (Z) seems fuzzier / less precise, so I'd like to hear your opinions. If you're comfortable using This is definitely something we should decide before 1.0. For now I'll document the |
tangent: another way to make this work would be to move the command expansion into a shell expression variable:
and then |
I think I've come up with a variant on Option (Y) that seems really simple and won't require changing shellexpand at all. This is currently my personal favorite, but I don't know if it's too subtle.
The difference between Option (Y) and Option (Y2) is that we don't need to change shellexpand to do it. We only need to perform a small string transformation before sending the values through the shellexpand machinery. The transformation is to do the A naive (slow) approach is to first replace all occurrences of A more direct transformation would be do a regex(?) replacement that transforms The reason this seems better is that it lets us have the best of both worlds. We can write I kinda like this idea the best. It is a breaking change, though, even though we never documented that If we think this is a good idea I can make that change and then consider this the final behavior that we'll support going forward. It feels like the right answer to me, at least. @grymoire7 I'd like to get your thoughts on this topic as well. Definitely let me know if this is something that would break any of your existing garden files or if you think the current behavior is better, for example. If it would break your existing files, but we still like the idea of changing the behavior, then I can build in a configuration option to restore the current behavior. Hopefully no one's run into this yet and we can just make the change without needing a config setting, though. |
@davvid I haven't rolled out garden to our entire team yet (still beta testing with the deploy coordinator on our initial use case), so we can easily pivot syntax at this point if needed. One thing that concerns me about Y2 are cases where the braces are required to avoid ambiguity. For example, with If that's correct, I think some kind of escaping solution might make more sense. Also, if a user wants to use |
Reserve the use of $shell variables for use by shell scripts. This makes it so that $shell references are not evaluated, but retaining the ${braced} shell expansion syntax for garden variables. Closes: #11 Signed-off-by: David Aguilar <[email protected]>
Related-to: #11 Signed-off-by: David Aguilar <[email protected]>
Reserve the use of $shell variables for use by shell scripts. This makes it so that $shell references are not evaluated, but retaining the ${braced} shell expansion syntax for garden variables. Closes: #11 Signed-off-by: David Aguilar <[email protected]>
Related-to: #11 Signed-off-by: David Aguilar <[email protected]>
Related-to: #11 Signed-off-by: David Aguilar <[email protected]>
Good point about As a proof of concept I implemented Y2 in #12. The braced I'll try testing out that syntax to see if there's a simple escape hatch we can use for |
Testing a bit with #12 I'm going to try and extend it so that we can use |
Extend the auto-escaping of "$" to allow escapign of ${braced} values by using double-"$" $${escaped} values. Related-to: #11 Signed-off-by: David Aguilar <[email protected]>
That was pretty easy -- thanks for pointing that out. #12 now has support for using This is now supported in #12
Thanks for your quick feedback. I think that might be the last thing we tweak before tagging the final v0.5.0. Good stuff. |
Extend the auto-escaping of "$" to allow escapign of ${braced} values by using double-"$" $${escaped} values. Related-to: #11 Signed-off-by: David Aguilar <[email protected]>
Wow, thanks for the fast turnaround on this! I think what you came up with is a good compromise and your doc updates in #12 make things very clear 👍. |
Related-to: #11 Signed-off-by: David Aguilar <[email protected]>
Extend the auto-escaping of "$" to allow escapign of ${braced} values by using double-"$" $${escaped} values. Related-to: #11 Signed-off-by: David Aguilar <[email protected]>
Thanks Nick, I think what we've got in #12 is just about ready to ship, so I'll plan to tag v0.5.0 final in the next day or so. |
* davvid/shell-variable-syntax: doc: document garden.shell Cargo.toml: garden v0.5.0-beta3 syntax: allow escaped $${variables} to disable evaluation changelog: update v0.5.0 release notes draft doc: add more command examples and document the $shell variable syntax syntax: allow $shell_variables to be used in shell commands eval: use shellexpand::full_with_context_no_errors() Closes #11 Signed-off-by: David Aguilar <[email protected]>
I have a use case that I haven't been able to figure out how to implement. I'd like to have a global command
unpushed
that goes through all my trees and prints out branch names for branches that aren't pushed upstream. I can list unpushed branches fine, but right now every tree gets a heading even if it doesn't have any unpushed branches. I'd like to be able to hide the headings for trees that don't have any unpushed branches. So for example:dev/advent-of-code
has an unpushed branch so its heading should be listed, butdev/bitcurry-provisioning
doesn't have any unpushed branches so I'd like to prevent having the heading printed.If there's not a way to do this, no big deal, but I figured I'd ask! This is a really great tool by the way!
The text was updated successfully, but these errors were encountered: