From 39329f6615f37ed65fcdd926f63563a60a5f60d9 Mon Sep 17 00:00:00 2001 From: geemus Date: Fri, 26 Apr 2024 15:51:08 -0500 Subject: [PATCH] v0.0.25: misc cleanup and fixes --- .github/workflows/release.yml | 5 +++ README.md | 2 +- api/api.go | 3 +- auth/models/whoami.go | 2 +- auth/testdata/TestWhoAmI/signed-in.golden | 5 ++- cli.go | 30 ++++++++++++++++++ cmd.go | 11 +++++-- cmd/anchor/main.go | 4 ++- go.mod | 2 +- lcl/config_test.go | 14 --------- lcl/lcl.go | 3 +- lcl/lcl_test.go | 14 --------- lcl/testdata/TestAudit/basics.golden | 8 ++--- lcl/testdata/TestClean/basics.golden | 6 ++-- lcl/testdata/TestLclConfig/basics.golden | 10 +++--- root.go | 13 +------- .../expected,_missing,_and_extra_CAs.golden | 2 +- trust/testdata/TestClean/basics.golden | 6 ++-- trust/testdata/TestTrust/basics.golden | 2 +- ui/driver.go | 15 +++++++-- ui/uitest/uitest.go | 6 ---- version/command.go | 10 +++--- version/command_test.go | 15 +++++---- .../TestCommand/golden-darwin_arm64.golden | 2 ++ .../golden-linux_amd64.golden} | 0 .../TestCommand/golden-windows_amd64.golden | 2 ++ version/version.go | 31 ++----------------- 27 files changed, 105 insertions(+), 118 deletions(-) create mode 100644 version/testdata/TestCommand/golden-darwin_arm64.golden rename version/testdata/{TestCommand.golden => TestCommand/golden-linux_amd64.golden} (100%) create mode 100644 version/testdata/TestCommand/golden-windows_amd64.golden diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0c2f21a..33936d1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -138,6 +138,11 @@ jobs: - shell: bash run: | cp cmd/anchor/dist/windows/anchor.${{ env.RELEASE_VERSION }}.nupkg ./ + - uses: actions/upload-artifact@v4 + with: + name: anchor.${{ env.RELEASE_VERSION }}.nupkg + overwrite: true + path: cmd/anchor/dist/windows/anchor.${{ env.RELEASE_VERSION }}.nupkg - shell: pwsh run: | diff --git a/README.md b/README.md index 9d7b442..2b04e55 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Available via [Chocolatey][] or as a downloadable binary from the [releases page Install: ``` -chocolatey install anchor --version=0.0.23 +chocolatey install anchor --version=0.0.22 ``` ### Install from source diff --git a/api/api.go b/api/api.go index 4863d13..f10472d 100644 --- a/api/api.go +++ b/api/api.go @@ -17,7 +17,6 @@ import ( "github.com/anchordotdev/cli" "github.com/anchordotdev/cli/keyring" - "github.com/anchordotdev/cli/version" "golang.org/x/exp/slices" ) @@ -370,7 +369,7 @@ type userAgentSetter struct { } func (s userAgentSetter) RoundTrip(req *http.Request) (*http.Response, error) { - req.Header.Set("User-Agent", version.UserAgent()) + req.Header.Set("User-Agent", cli.UserAgent()) return s.RoundTripper.RoundTrip(req) } diff --git a/auth/models/whoami.go b/auth/models/whoami.go index 9f730ef..50d7401 100644 --- a/auth/models/whoami.go +++ b/auth/models/whoami.go @@ -39,7 +39,7 @@ func (m *WhoAmIChecker) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case UserWhoAmIMsg: m.whoami = string(msg) - return m, tea.Quit + return m, nil } var cmd tea.Cmd diff --git a/auth/testdata/TestWhoAmI/signed-in.golden b/auth/testdata/TestWhoAmI/signed-in.golden index b3d5e44..4d53f76 100644 --- a/auth/testdata/TestWhoAmI/signed-in.golden +++ b/auth/testdata/TestWhoAmI/signed-in.golden @@ -2,4 +2,7 @@ # Identify Current Anchor.dev Account `anchor auth whoami` ─── WhoAmIChecker ────────────────────────────────────────────────────────────── # Identify Current Anchor.dev Account `anchor auth whoami` - * Identifying Anchor.dev account… * + * Identifying Anchor.dev account… ⠋ +─── WhoAmIChecker ────────────────────────────────────────────────────────────── +# Identify Current Anchor.dev Account `anchor auth whoami` + - Identified Anchor.dev account: anky@anchor.dev diff --git a/cli.go b/cli.go index 87c41dc..2b49094 100644 --- a/cli.go +++ b/cli.go @@ -2,11 +2,41 @@ package cli import ( "context" + "fmt" + "runtime" "github.com/anchordotdev/cli/ui" "github.com/spf13/cobra" ) +var Version = struct { + Version, Commit, Date string + + Os, Arch string +}{ + Version: "dev", + Commit: "none", + Date: "unknown", + Os: runtime.GOOS, + Arch: runtime.GOARCH, +} + +func IsDevVersion() bool { + return Version.Version == "dev" +} + +func UserAgent() string { + return "Anchor CLI " + VersionString() +} + +func ReleaseTagName() string { + return fmt.Sprintf("v%s", Version.Version) +} + +func VersionString() string { + return fmt.Sprintf("%s (%s/%s) Commit: %s BuildDate: %s", Version.Version, Version.Os, Version.Arch, Version.Commit, Version.Date) +} + type Config struct { JSON bool `desc:"Only print JSON output to STDOUT." flag:"json,j" env:"JSON_OUTPUT" toml:"json-output"` NonInteractive bool `desc:"Run without ever asking for user input." flag:"non-interactive,n" env:"NON_INTERACTIVE" toml:"non-interactive"` diff --git a/cmd.go b/cmd.go index 32fd266..92acf55 100644 --- a/cmd.go +++ b/cmd.go @@ -245,12 +245,20 @@ func NewCmd[T UIer](parent *cobra.Command, name string, fn func(*cobra.Command)) panic(err) } - cmd.RunE = func(cmd *cobra.Command, _ []string) error { + cmd.RunE = func(cmd *cobra.Command, args []string) error { cfg := ConfigFromCmd(cmd) if cfg.Test.SkipRunE { return nil } + var t T + + switch any(t).(type) { + case ShowHelp: + cmd.HelpFunc()(cmd, args) + return nil + } + ctx, cancel := context.WithCancelCause(cmd.Context()) defer cancel(nil) @@ -266,7 +274,6 @@ func NewCmd[T UIer](parent *cobra.Command, name string, fn func(*cobra.Command)) errc <- err }() - var t T if err := t.UI().RunTUI(ctx, drv); err != nil && err != context.Canceled { prg.Quit() diff --git a/cmd/anchor/main.go b/cmd/anchor/main.go index cb38142..cc4e7fb 100644 --- a/cmd/anchor/main.go +++ b/cmd/anchor/main.go @@ -21,7 +21,9 @@ var ( func init() { if version != "" { - versionpkg.Set(version, commit, date) + cli.Version.Commit = commit + cli.Version.Date = date + cli.Version.Version = version } cli.CmdRoot.PersistentPreRunE = versionpkg.VersionCheck } diff --git a/go.mod b/go.mod index 6fcab75..551ed74 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,6 @@ require ( github.com/muesli/termenv v0.15.2 github.com/oapi-codegen/runtime v1.1.1 github.com/spf13/cobra v1.8.0 - github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 github.com/zalando/go-keyring v0.2.4 golang.org/x/crypto v0.21.0 @@ -64,6 +63,7 @@ require ( github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect + github.com/spf13/pflag v1.0.5 // indirect golang.org/x/mod v0.16.0 // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.16.0 // indirect diff --git a/lcl/config_test.go b/lcl/config_test.go index 84a68e6..36c1e84 100644 --- a/lcl/config_test.go +++ b/lcl/config_test.go @@ -112,20 +112,6 @@ func TestLclConfig(t *testing.T) { t.Skip("diagnostic unsupported in mock mode") } - teatest.WaitFor( - t, drv.Out, - func(bts []byte) bool { - if len(errc) > 0 { - t.Fatal(<-errc) - } - - expect := "Entered hello-world.lcl.host domain for lcl.host diagnostic certificate." - return bytes.Contains(bts, []byte(expect)) - }, - teatest.WithCheckInterval(time.Millisecond*100), - teatest.WithDuration(time.Second*3), - ) - teatest.WaitFor( t, drv.Out, func(bts []byte) bool { diff --git a/lcl/lcl.go b/lcl/lcl.go index 60cc7fc..d84d7b1 100644 --- a/lcl/lcl.go +++ b/lcl/lcl.go @@ -14,7 +14,6 @@ import ( "github.com/anchordotdev/cli/auth" "github.com/anchordotdev/cli/lcl/models" "github.com/anchordotdev/cli/ui" - "github.com/anchordotdev/cli/version" "github.com/spf13/cobra" ) @@ -127,7 +126,7 @@ func provisionCert(eab *api.Eab, domains []string, acmeURL string) (*tls.Certifi HostPolicy: autocert.HostWhitelist(domains...), Client: &acme.Client{ DirectoryURL: acmeURL, - UserAgent: version.UserAgent(), + UserAgent: cli.UserAgent(), }, ExternalAccountBinding: &acme.ExternalAccountBinding{ KID: eab.Kid, diff --git a/lcl/lcl_test.go b/lcl/lcl_test.go index 2a3e7fe..56219b3 100644 --- a/lcl/lcl_test.go +++ b/lcl/lcl_test.go @@ -163,20 +163,6 @@ func TestLcl(t *testing.T) { t.Skip("diagnostic unsupported in mock mode") } - teatest.WaitFor( - t, drv.Out, - func(bts []byte) bool { - if len(errc) > 0 { - t.Fatal(<-errc) - } - - expect := "Entered hello-world.lcl.host domain for lcl.host diagnostic certificate." - return bytes.Contains(bts, []byte(expect)) - }, - teatest.WithCheckInterval(time.Millisecond*100), - teatest.WithDuration(time.Second*3), - ) - teatest.WaitFor( t, drv.Out, func(bts []byte) bool { diff --git a/lcl/testdata/TestAudit/basics.golden b/lcl/testdata/TestAudit/basics.golden index b8af6f0..d9beaa9 100644 --- a/lcl/testdata/TestAudit/basics.golden +++ b/lcl/testdata/TestAudit/basics.golden @@ -1,7 +1,7 @@ ─── Client ───────────────────────────────────────────────────────────────────── - * Checking authentication: probing credentials locally…* + * Checking authentication: probing credentials locally…⠋ ─── Client ───────────────────────────────────────────────────────────────────── - * Checking authentication: testing credentials remotely…* + * Checking authentication: testing credentials remotely…⠋ ─── AuditHeader ──────────────────────────────────────────────────────────────── # Audit lcl.host HTTPS Local Development Environment `anchor lcl audit` ─── AuditHint ────────────────────────────────────────────────────────────────── @@ -10,7 +10,7 @@ ─── AuditResources ───────────────────────────────────────────────────────────── # Audit lcl.host HTTPS Local Development Environment `anchor lcl audit` | We'll begin by checking your system to determine what you need for your setup. - * Checking resources on Anchor.dev…* + * Checking resources on Anchor.dev…⠋ ─── AuditResources ───────────────────────────────────────────────────────────── # Audit lcl.host HTTPS Local Development Environment `anchor lcl audit` | We'll begin by checking your system to determine what you need for your setup. @@ -19,7 +19,7 @@ # Audit lcl.host HTTPS Local Development Environment `anchor lcl audit` | We'll begin by checking your system to determine what you need for your setup. - Checked resources on Anchor.dev: need to provision resources. - * Scanning local and expected CA certificates…* + * Scanning local and expected CA certificates…⠋ ─── AuditTrust ───────────────────────────────────────────────────────────────── # Audit lcl.host HTTPS Local Development Environment `anchor lcl audit` | We'll begin by checking your system to determine what you need for your setup. diff --git a/lcl/testdata/TestClean/basics.golden b/lcl/testdata/TestClean/basics.golden index b0ba151..e610809 100644 --- a/lcl/testdata/TestClean/basics.golden +++ b/lcl/testdata/TestClean/basics.golden @@ -1,7 +1,7 @@ ─── Client ───────────────────────────────────────────────────────────────────── - * Checking authentication: probing credentials locally…* + * Checking authentication: probing credentials locally…⠋ ─── Client ───────────────────────────────────────────────────────────────────── - * Checking authentication: testing credentials remotely…* + * Checking authentication: testing credentials remotely…⠋ ─── LclCleanHeader ───────────────────────────────────────────────────────────── # Clean lcl.host CA Certificates from Local Trust Store(s) `anchor trust clean` ─── LclCleanHint ─────────────────────────────────────────────────────────────── @@ -10,7 +10,7 @@ ─── TrustCleanAudit ──────────────────────────────────────────────────────────── # Clean lcl.host CA Certificates from Local Trust Store(s) `anchor trust clean` | Removing lcl.host CA certificates from the mock store(s). - * Auditing local CA certificates…* + * Auditing local CA certificates…⠋ ─── TrustCleanAudit ──────────────────────────────────────────────────────────── # Clean lcl.host CA Certificates from Local Trust Store(s) `anchor trust clean` | Removing lcl.host CA certificates from the mock store(s). diff --git a/lcl/testdata/TestLclConfig/basics.golden b/lcl/testdata/TestLclConfig/basics.golden index cb3eac4..b9bacd7 100644 --- a/lcl/testdata/TestLclConfig/basics.golden +++ b/lcl/testdata/TestLclConfig/basics.golden @@ -1,7 +1,7 @@ ─── Client ───────────────────────────────────────────────────────────────────── - * Checking authentication: probing credentials locally…* + * Checking authentication: probing credentials locally…⠋ ─── Client ───────────────────────────────────────────────────────────────────── - * Checking authentication: testing credentials remotely…* + * Checking authentication: testing credentials remotely…⠋ ─── LclConfigHeader ──────────────────────────────────────────────────────────── # Configure System for lcl.host HTTPS Local Development `anchor lcl config` ─── LclConfigHint ────────────────────────────────────────────────────────────── @@ -132,7 +132,7 @@ | | We'll start a local diagnostic web server to guide you through the process. - Entered hello-world.lcl.host domain for lcl.host diagnostic certificate. - * Resolving hello-world.lcl.host domain…* + * Resolving hello-world.lcl.host domain…⠋ ─── DomainResolver ───────────────────────────────────────────────────────────── # Configure System for lcl.host HTTPS Local Development `anchor lcl config` | Before issuing HTTPS certificates for your local applications, we need to @@ -151,7 +151,7 @@ - Resolved hello-world.lcl.host domain: success! | Now we'll provision your application's resources on Anchor.dev and the HTTPS | certificates for your development environment. - - Creating hello-world [hello-world.lcl.host, hello-world.localhost] diagnostic resources on Anchor.dev… * + - Creating hello-world [hello-world.lcl.host, hello-world.localhost] diagnostic resources on Anchor.dev… ⠋ ─── ProvisionService ─────────────────────────────────────────────────────────── # Configure System for lcl.host HTTPS Local Development `anchor lcl config` | Before issuing HTTPS certificates for your local applications, we need to @@ -203,7 +203,7 @@ - Great, http://hello-world.lcl.host:4433 works as expected (without HTTPS). | Next, we'll add your personal CA certificates to your system's trust stores. | This may require sudo privileges, learn why here: https://lcl.host/why-sudo - * Comparing local and expected CA certificates…* + * Comparing local and expected CA certificates…⠋ ─── TrustPreflight ───────────────────────────────────────────────────────────── # Configure System for lcl.host HTTPS Local Development `anchor lcl config` | Before issuing HTTPS certificates for your local applications, we need to diff --git a/root.go b/root.go index f88dfd4..314b9f8 100644 --- a/root.go +++ b/root.go @@ -1,12 +1,7 @@ package cli import ( - "context" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - - "github.com/anchordotdev/cli/ui" ) var CmdRoot = NewCmd[ShowHelp](nil, "anchor", func(cmd *cobra.Command) {}) @@ -14,11 +9,5 @@ var CmdRoot = NewCmd[ShowHelp](nil, "anchor", func(cmd *cobra.Command) {}) type ShowHelp struct{} func (c ShowHelp) UI() UI { - return UI{ - RunTUI: c.RunTUI, - } -} - -func (c ShowHelp) RunTUI(ctx context.Context, drv *ui.Driver) error { - return pflag.ErrHelp + return UI{} } diff --git a/trust/testdata/TestAudit/expected,_missing,_and_extra_CAs.golden b/trust/testdata/TestAudit/expected,_missing,_and_extra_CAs.golden index 458a68c..20b1459 100644 --- a/trust/testdata/TestAudit/expected,_missing,_and_extra_CAs.golden +++ b/trust/testdata/TestAudit/expected,_missing,_and_extra_CAs.golden @@ -2,7 +2,7 @@ # Audit CA Certificates in Your Local Trust Store(s) `anchor trust audit` ─── TrustAuditScan ───────────────────────────────────────────────────────────── # Audit CA Certificates in Your Local Trust Store(s) `anchor trust audit` - * Scanning local and expected CA certificates…* + * Scanning local and expected CA certificates…⠋ ─── TrustAuditScan ───────────────────────────────────────────────────────────── # Audit CA Certificates in Your Local Trust Store(s) `anchor trust audit` - Scanned local and expected CA certificates. diff --git a/trust/testdata/TestClean/basics.golden b/trust/testdata/TestClean/basics.golden index e7df422..abfac2f 100644 --- a/trust/testdata/TestClean/basics.golden +++ b/trust/testdata/TestClean/basics.golden @@ -1,7 +1,7 @@ ─── Client ───────────────────────────────────────────────────────────────────── - * Checking authentication: probing credentials locally…* + * Checking authentication: probing credentials locally…⠋ ─── Client ───────────────────────────────────────────────────────────────────── - * Checking authentication: testing credentials remotely…* + * Checking authentication: testing credentials remotely…⠋ ─── TrustCleanHeader ─────────────────────────────────────────────────────────── # Clean CA Certificates from Local Trust Store(s) `anchor trust clean` ─── TrustCleanHint ───────────────────────────────────────────────────────────── @@ -10,7 +10,7 @@ ─── TrustCleanAudit ──────────────────────────────────────────────────────────── # Clean CA Certificates from Local Trust Store(s) `anchor trust clean` | Removing CA certificates from the mock store(s). - * Auditing local CA certificates…* + * Auditing local CA certificates…⠋ ─── TrustCleanAudit ──────────────────────────────────────────────────────────── # Clean CA Certificates from Local Trust Store(s) `anchor trust clean` | Removing CA certificates from the mock store(s). diff --git a/trust/testdata/TestTrust/basics.golden b/trust/testdata/TestTrust/basics.golden index 11fef20..1f8ac40 100644 --- a/trust/testdata/TestTrust/basics.golden +++ b/trust/testdata/TestTrust/basics.golden @@ -1,5 +1,5 @@ ─── TrustPreflight ───────────────────────────────────────────────────────────── - * Comparing local and expected CA certificates…* + * Comparing local and expected CA certificates…⠋ ─── TrustPreflight ───────────────────────────────────────────────────────────── - Compared local and expected CA certificates: need to install 2 missing certificates. ! Installing 2 missing certificates. (requires sudo) diff --git a/ui/driver.go b/ui/driver.go index 6b7a968..e6bc10f 100644 --- a/ui/driver.go +++ b/ui/driver.go @@ -14,6 +14,14 @@ import ( "github.com/muesli/termenv" ) +var ( + spinnerReplacer = strings.NewReplacer(strings.Split(spinnerCharacters, ",")...) + + waitingFrames = WaitingSpinner().Spinner.Frames + replacementFrame = waitingFrames[0] + spinnerCharacters = strings.Join(waitingFrames, ","+replacementFrame+",") + "," + replacementFrame +) + type Program interface { Quit() Run() (tea.Model, error) @@ -159,12 +167,13 @@ func (d *Driver) View() string { for _, mdl := range d.models { out += mdl.View() } - if d.test && out != "" && out != d.lastView { + normalizedOut := spinnerReplacer.Replace(out) + if d.test && out != "" && normalizedOut != d.lastView { separator := "─── " + reflect.TypeOf(d.active).Elem().Name() + " " separator = separator + strings.Repeat("─", 80-utf8.RuneCountInString(separator)) fmt.Fprintln(d.out, separator) - fmt.Fprint(d.out, out) - d.lastView = out + fmt.Fprint(d.out, normalizedOut) + d.lastView = normalizedOut } return out } diff --git a/ui/uitest/uitest.go b/ui/uitest/uitest.go index f0b7355..43f8726 100644 --- a/ui/uitest/uitest.go +++ b/ui/uitest/uitest.go @@ -6,7 +6,6 @@ import ( "testing" "time" - "github.com/charmbracelet/bubbles/spinner" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/x/exp/teatest" @@ -20,11 +19,6 @@ import ( func init() { lipgloss.SetColorProfile(termenv.Ascii) // no color for consistent golden file lipgloss.SetHasDarkBackground(false) // dark background for consistent golden file - - ui.Waiting = spinner.Spinner{ - Frames: []string{"*"}, - FPS: time.Second / 100, - } } func TestTUI(ctx context.Context, t *testing.T) (*ui.Driver, *teatest.TestModel) { diff --git a/version/command.go b/version/command.go index 319eed5..be8a7ae 100644 --- a/version/command.go +++ b/version/command.go @@ -22,11 +22,11 @@ func (c Command) UI() cli.UI { func (c Command) runTUI(ctx context.Context, drv *ui.Driver) error { drv.Activate(ctx, &models.Version{ - Arch: info.arch, - Commit: info.commit, - Date: info.date, - OS: info.os, - Version: info.version, + Arch: cli.Version.Arch, + Commit: cli.Version.Commit, + Date: cli.Version.Date, + OS: cli.Version.Os, + Version: cli.Version.Version, }) return nil diff --git a/version/command_test.go b/version/command_test.go index e1644c0..34912d8 100644 --- a/version/command_test.go +++ b/version/command_test.go @@ -3,6 +3,7 @@ package version import ( "context" "flag" + "fmt" "runtime" "testing" @@ -22,14 +23,12 @@ func TestCmdVersion(t *testing.T) { } func TestCommand(t *testing.T) { - if runtime.GOOS != "linux" { - t.Skip("only run version test on linux since OS is in output") - } + t.Run(fmt.Sprintf("golden-%s_%s", runtime.GOOS, runtime.GOARCH), func(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() + cmd := Command{} - cmd := new(Command) - - uitest.TestTUIOutput(ctx, t, cmd.UI()) + uitest.TestTUIOutput(ctx, t, cmd.UI()) + }) } diff --git a/version/testdata/TestCommand/golden-darwin_arm64.golden b/version/testdata/TestCommand/golden-darwin_arm64.golden new file mode 100644 index 0000000..5e1fbfc --- /dev/null +++ b/version/testdata/TestCommand/golden-darwin_arm64.golden @@ -0,0 +1,2 @@ +─── Version ──────────────────────────────────────────────────────────────────── +dev (darwin/arm64) Commit: none BuildDate: unknown diff --git a/version/testdata/TestCommand.golden b/version/testdata/TestCommand/golden-linux_amd64.golden similarity index 100% rename from version/testdata/TestCommand.golden rename to version/testdata/TestCommand/golden-linux_amd64.golden diff --git a/version/testdata/TestCommand/golden-windows_amd64.golden b/version/testdata/TestCommand/golden-windows_amd64.golden new file mode 100644 index 0000000..2fd61ca --- /dev/null +++ b/version/testdata/TestCommand/golden-windows_amd64.golden @@ -0,0 +1,2 @@ +─── Version ──────────────────────────────────────────────────────────────────── +dev (windows/amd64) Commit: none BuildDate: unknown diff --git a/version/version.go b/version/version.go index 398c90b..a245419 100644 --- a/version/version.go +++ b/version/version.go @@ -6,40 +6,15 @@ import ( "runtime" "time" + "github.com/anchordotdev/cli" "github.com/anchordotdev/cli/ui" "github.com/atotto/clipboard" "github.com/google/go-github/v54/github" "github.com/spf13/cobra" ) -var info = struct { - version, commit, date string - - os, arch string -}{ - version: "dev", - commit: "none", - date: "unknown", - os: runtime.GOOS, - arch: runtime.GOARCH, -} - -func Set(version, commit, date string) { - info.version = version - info.commit = commit - info.date = date -} - -func String() string { - return fmt.Sprintf("%s (%s/%s) Commit: %s BuildDate: %s", info.version, info.os, info.arch, info.commit, info.date) -} - -func UserAgent() string { - return "Anchor CLI " + String() -} - func VersionCheck(cmd *cobra.Command, args []string) error { - if info.version == "dev" { + if cli.IsDevVersion() { return nil } @@ -53,7 +28,7 @@ func VersionCheck(cmd *cobra.Command, args []string) error { return nil } - if release.TagName == nil || *release.TagName != "v"+info.version { + if release.TagName == nil || *release.TagName != cli.ReleaseTagName() { fmt.Println(ui.StepHint("A new release of the anchor CLI is available.")) if !isWindowsRuntime() { command := "brew update && brew upgrade anchor"