Skip to content

Commit

Permalink
Change command pkg to build pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
samcoe committed Oct 21, 2020
1 parent 0f8084d commit 9df3bd9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions command/root.go → build/build.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package command
package build

import (
"runtime/debug"
Expand All @@ -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" {
Expand Down
20 changes: 11 additions & 9 deletions cmd/gh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}()

Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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"))

Expand Down Expand Up @@ -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
}
Expand All @@ -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 == "" {
Expand Down

0 comments on commit 9df3bd9

Please sign in to comment.