-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Add a gh variable get FOO
command
#9106
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@williammartin I think adding the newline could be a problem in scripting.
When doing stuff like
FOO=$(gh variable get MY_VAR)
Now the trailing newline would be part of the variable. Of course, I could trim the trailing newline, but it's inconvenient and not obvious.
It's nice when the variable is displayed in the terminal (but if the variable actually had a newline already, you would get an extra).
A solution for increased readability in the terminal could be to add a newline but add it to stderr, if and only if the variable already lacks a trailing newline and both stdout and stderr are to the terminal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well...this sent me on a bit of a journey. Firstly, I appreciate your comment and sorry that I didn't recognise there was more to discuss here.
Command Substitution
I don't believe that your first example is an issue because command substitution (
$()
) removes trailing line feed characters:Thus, our addition of a
\n
in thefmt.Printf
should have no impact onFOO=$(gh variable get MY_VAR)
. This is consistent with othergh
commands when not hooked up to a TTY but printing info e.g.repo create
showing the newly created repo URL.This also makes sense from a UX point of view as well because in CI or scripts we wouldn't want users to have to add newlines everywhere in order to avoid text appearing concatenated together with no spacing.
However....
It did get me wondering about your other comment relating to variables ending with newlines. If command substitution strips trailing Line Feed chars then that will be problematic for variables that have trailing new lines:
So this leaves us in an interesting situation because for variables ending in newlines, command substitution is a bit of a nightmare. There does appear to be some workarounds however in that case it's probably not possible for a user to distinguish between their own newlines and the one added by the CLI.
However, I'm inclined to say that in this particular case, we document it and place the responsibility on the user to strip our trailing newline before processing the string because the alternative and much more common case seems quite annoying (strings being concatenated together and it working differently from other commands).
Finally
I'm inclined to say there is a bug in both
secret set
andvariable set
when reading the variable value from stdin. It looks like in #5086 we decided to trim carriage return and line feed chars from the end because the shell adds one but the implementation actually strips all trailing CR/LF chars:Let me know your thoughts, cheers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. I didn't know command substitution removes trailing newlines.
It might just have been me being too careful about not loosing my scripting capabilities.
So adding the newline seems perfectly inline with what would normally be expected. I'm not sure, removing the newlines in command substitution was the world's best idea (looking at the workarounds, among others) but that should probably have been handled 45 years ago by someone not me or you 😄