diff --git a/Makefile b/Makefile index 075a8865e..35837205e 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ ifndef CGO_LDFLAGS export CGO_LDFLAGS := $(LDFLAGS) endif -GO_LDFLAGS := -X github.com/cli/cli/command.Version=$(GH_VERSION) $(GO_LDFLAGS) -GO_LDFLAGS := -X github.com/cli/cli/command.BuildDate=$(BUILD_DATE) $(GO_LDFLAGS) +GO_LDFLAGS := -X github.com/cli/cli/build.Version=$(GH_VERSION) $(GO_LDFLAGS) +GO_LDFLAGS := -X github.com/cli/cli/build.Date=$(BUILD_DATE) $(GO_LDFLAGS) ifdef GH_OAUTH_CLIENT_SECRET GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientID=$(GH_OAUTH_CLIENT_ID) $(GO_LDFLAGS) GO_LDFLAGS := -X github.com/cli/cli/internal/authflow.oauthClientSecret=$(GH_OAUTH_CLIENT_SECRET) $(GO_LDFLAGS) diff --git a/command/root.go b/build/build.go similarity index 71% rename from command/root.go rename to build/build.go index 5660196e7..8c3e78a7e 100644 --- a/command/root.go +++ b/build/build.go @@ -1,4 +1,4 @@ -package command +package build import ( "runtime/debug" @@ -7,8 +7,8 @@ import ( // Version is dynamically set by the toolchain or overridden by the Makefile. var Version = "DEV" -// BuildDate is dynamically set at build time in the Makefile. -var BuildDate = "" // YYYY-MM-DD +// Date is dynamically set at build time in the Makefile. +var Date = "" // YYYY-MM-DD func init() { if Version == "DEV" { diff --git a/cmd/gh/main.go b/cmd/gh/main.go index 17b3a644e..4d29709c4 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -12,7 +12,7 @@ import ( surveyCore "github.com/AlecAivazis/survey/v2/core" "github.com/cli/cli/api" - "github.com/cli/cli/command" + "github.com/cli/cli/build" "github.com/cli/cli/internal/config" "github.com/cli/cli/internal/ghinstance" "github.com/cli/cli/internal/run" @@ -29,10 +29,12 @@ import ( var updaterEnabled = "" func main() { - currentVersion := command.Version + buildDate := build.Date + buildVersion := build.Version + updateMessageChan := make(chan *update.ReleaseInfo) go func() { - rel, _ := checkForUpdate(currentVersion) + rel, _ := checkForUpdate(buildVersion) updateMessageChan <- rel }() @@ -42,7 +44,7 @@ func main() { ghinstance.OverrideDefault(hostFromEnv) } - cmdFactory := factory.New(command.Version) + cmdFactory := factory.New(buildVersion) stderr := cmdFactory.IOStreams.ErrOut if !cmdFactory.IOStreams.ColorEnabled() { surveyCore.DisableColor = true @@ -61,7 +63,7 @@ func main() { } } - rootCmd := root.NewCmdRoot(cmdFactory, command.Version, command.BuildDate) + rootCmd := root.NewCmdRoot(cmdFactory, buildVersion, buildDate) cfg, err := cmdFactory.Config() if err != nil { @@ -151,7 +153,7 @@ func main() { if newRelease != nil { msg := fmt.Sprintf("%s %s → %s\n%s", ansi.Color("A new release of gh is available:", "yellow"), - ansi.Color(currentVersion, "cyan"), + ansi.Color(buildVersion, "cyan"), ansi.Color(newRelease.Version, "cyan"), ansi.Color(newRelease.URL, "yellow")) @@ -208,7 +210,7 @@ func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) { return nil, nil } - client, err := basicClient() + client, err := basicClient(currentVersion) if err != nil { return nil, err } @@ -220,12 +222,12 @@ func checkForUpdate(currentVersion string) (*update.ReleaseInfo, error) { // BasicClient returns an API client for github.com only that borrows from but // does not depend on user configuration -func basicClient() (*api.Client, error) { +func basicClient(currentVersion string) (*api.Client, error) { var opts []api.ClientOption if verbose := os.Getenv("DEBUG"); verbose != "" { opts = append(opts, apiVerboseLog()) } - opts = append(opts, api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", command.Version))) + opts = append(opts, api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", currentVersion))) token := os.Getenv("GITHUB_TOKEN") if token == "" {