Skip to content
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 gh variable get command #9103

Closed
arnested opened this issue May 21, 2024 · 10 comments · Fixed by #9106
Closed

Add gh variable get command #9103

arnested opened this issue May 21, 2024 · 10 comments · Fixed by #9106
Labels
enhancement a request to improve CLI gh-variable relating to the gh variable command help wanted Contributions welcome

Comments

@arnested
Copy link
Contributor

Describe the feature or problem you’d like to solve

It's currently possible to set a variable using, e.g., gh variable set FOO --body=BAR.

And it's possible to list all variables using:

$ gh variable list
NAME           VALUE       UPDATED             
FOO            BAR         about 12 minutes ago

It's not possible, though, to read a single variable using, e.g., gh variable get FOO.

It is possible to achieve using:

$ gh variable list --json name,value --jq '.[] | select( .name | contains("FOO")).value'
BAR

I'm pretty sure I won't be able to remember that command when I need it. And I'm pretty sure it'll require a lot of brain cycles to read and understand it.

Proposed solution

I propose to add a gh variable get FOO.

@arnested arnested added the enhancement a request to improve CLI label May 21, 2024
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label May 21, 2024
@williammartin williammartin added the gh-variable relating to the gh variable command label May 21, 2024
@williammartin
Copy link
Member

Thanks for the enhancement request. It seems like an obvious addition, I wonder why it wasn't there to begin with. However, no one has asked for it! It looks like in one of the original PRs for the gh variable list command it was possible to filter by name, but I can't find any place that this was discussed for removal.

Can you describe your use case a little bit more? It's useful to us to know how people are using the CLI commands to help us understand the bigger picture.

@williammartin williammartin added needs-user-input and removed needs-triage needs to be reviewed labels May 21, 2024
@arnested
Copy link
Contributor Author

Can you describe your use case a little bit more? It's useful to us to know how people are using the CLI commands to help us understand the bigger picture.

We are currently building an internal "starter kit" where we use some shell scripts to set up the individual projects.

These script store some data in variables (e.g., which Jira projects a repository is connected to) and this info is then used by GitHub Action workflows.

It's no problem to set the variables using gh variable set but I would like to get them first to make sure we don't override data from a previous run (and to be able to reuse already set data in other scripts).

@williammartin
Copy link
Member

Thanks!

It's no problem to set the variables using gh variable set but I would like to get them first to make sure we don't override data from a previous run (and to be able to reuse already set data in other scripts).

So if I understand correctly there are two outcomes:

  1. Don't overwrite variables that may have been previously set by other scripts
  2. Use the value of previously set variables in your script going forward

That makes sense. I wondered whether gh variable set --no-clobber would help with 1. and be less prone to race conditions, but if you also really need the variables then 2. seems worthwhile as well. Thanks for letting me know.

@arnested
Copy link
Contributor Author

In theory, I have race conditions, yes. In practice, probably not.

Both solutions would be useful.

I guess the current lack of a get command could possibly be that variables was based on secret and there it's most likely by design it has been left out (for secrets it's not listing the values using list either).

@williammartin
Copy link
Member

I guess the current lack of a get command could possibly be that variables was based on secret and there it's most likely by design it has been left out (for secrets it's not listing the values using list either).

Yeh that's my suspicion as well. In the absence of any other obvious reason appearing, this seems like a good addition to me. I'm going to label it help wanted in case you or anyone else is interested in contributing.

@williammartin williammartin added help wanted Contributions welcome and removed needs-user-input labels May 21, 2024
arnested added a commit to arnested/cli-1 that referenced this issue May 21, 2024
@arnested
Copy link
Contributor Author

Ok, I took a stab at it. It's heavily based on the gh variable list and gh variable delete commands. I think I managed to keep what was needed and remove unwanted stuff.

williammartin added a commit that referenced this issue May 23, 2024
Closes #9103.

---------

Co-authored-by: William Martin <williammartin@github.com>
@williammartin williammartin changed the title gh variable get Add gh variable get command May 23, 2024
@williammartin
Copy link
Member

I created #9118 as a follow up on this if you're interested in having a look at it I can point you in the right direction but no worries if you're not interested. Thanks!

@arnested
Copy link
Contributor Author

Thank you, @williammartin!

I wanted to take a look at #9118 today, but I can see @babakks beat me to it. Thank you, @babakks!

@babakks
Copy link
Contributor

babakks commented May 26, 2024

@arnested Sorry, I didn't notice this comment here. I was just looking for help-wanted issues. By the way, kudos for adding the variable get command.

@arnested
Copy link
Contributor Author

No need to be sorry, @babakks 😄

I didn't really have the time anyway 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a request to improve CLI gh-variable relating to the gh variable command help wanted Contributions welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@arnested @williammartin @babakks @cliAutomation and others