Skip to content

Add --version flag support#40

Merged
mislav merged 3 commits intomasterfrom
version-flag
Oct 31, 2019
Merged

Add --version flag support#40
mislav merged 3 commits intomasterfrom
version-flag

Conversation

@mislav
Copy link
Copy Markdown
Contributor

@mislav mislav commented Oct 31, 2019

gh --version => "gh version VERSION (DATE)"

  • VERSION: git tag (if exactly on a tagged commit), or git sha
  • DATE: build date

@tierninho
Copy link
Copy Markdown
Contributor

Thanks for adding this, I have been hoping this will land.

Two questions:

  • will gh -v expected to also work?
  • should a note be made in the gh - help page about how to check the version?

Idea: add in a link to the release notes like gh --version => "gh version VERSION (DATE) (LINK)"

@mislav
Copy link
Copy Markdown
Contributor Author

mislav commented Oct 31, 2019

  • will gh -v expected to also work?

It doesn't work right now, and maybe we could make it work (not sure if our CLI framework enables that), but I don't feel like it's strictly needed. Because sometimes -v means "verbose" or another flag, commands usually settle for long-form --version or version to display a version. Git, for instance, doesn't support -v.

  • should a note be made in the gh - help page about how to check the version?

That's a good point! Our CLI framework ensures that it's already there:

Usage:
  gh [command]

Available Commands:
  help        Help about any command
  pr          Work with pull requests

Flags:
  -B, --current-branch string   current git branch
  -h, --help                    help for gh
  -R, --repo string             current GitHub repository
      --version                 version for gh

Copy link
Copy Markdown
Contributor

@probablycorey probablycorey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# export GOFLAGS := -mod=vendor $GOFLAGS
GH_VERSION = $(shell go describe --tags 2>/dev/null || git rev-parse --short HEAD)
LDFLAGS := -X github.com/github/gh-cli/command.Version=$(GH_VERSION) $(LDFLAGS)
LDFLAGS := -X github.com/github/gh-cli/command.BuildDate=$(shell date +%Y-%m-%d) $(LDFLAGS)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woah, this linker trick is super cool and handy!

command/root.go Outdated
// Version is dynamically set at build time
var Version = "DEV"

// BuildDate is dynamically set at build time
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to say where the dynamic part happens, like "BuildDate is dynamically set at build time in the Makefile"

@mislav mislav merged commit 4c76f5c into master Oct 31, 2019
@mislav mislav deleted the version-flag branch October 31, 2019 22:13
vilmibm pushed a commit that referenced this pull request Jun 29, 2021
Refactored output, the tests, and the use of opts in runBrowse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants