Skip to content

Commit

Permalink
v0.0.25: misc cleanup and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Apr 26, 2024
1 parent 14a61f0 commit 39329f6
Show file tree
Hide file tree
Showing 27 changed files with 105 additions and 118 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/anchordotdev/cli"
"github.com/anchordotdev/cli/keyring"
"github.com/anchordotdev/cli/version"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion auth/models/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion auth/testdata/TestWhoAmI/signed-in.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
30 changes: 30 additions & 0 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
11 changes: 9 additions & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()

Expand Down
4 changes: 3 additions & 1 deletion cmd/anchor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions lcl/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions lcl/lcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions lcl/lcl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions lcl/testdata/TestAudit/basics.golden
Original file line number Diff line number Diff line change
@@ -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 ──────────────────────────────────────────────────────────────────
Expand All @@ -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.
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions lcl/testdata/TestClean/basics.golden
Original file line number Diff line number Diff line change
@@ -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 ───────────────────────────────────────────────────────────────
Expand All @@ -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).
Expand Down
10 changes: 5 additions & 5 deletions lcl/testdata/TestLclConfig/basics.golden
Original file line number Diff line number Diff line change
@@ -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 ──────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 1 addition & 12 deletions root.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
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) {})

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{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions trust/testdata/TestClean/basics.golden
Original file line number Diff line number Diff line change
@@ -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 ─────────────────────────────────────────────────────────────
Expand All @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion trust/testdata/TestTrust/basics.golden
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
15 changes: 12 additions & 3 deletions ui/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 39329f6

Please sign in to comment.