Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ builds:
flags:
- -trimpath
ldflags:
- -s -w -X github.com/localstack/lstk/internal/version.version={{ .Version }} -X github.com/localstack/lstk/internal/version.commit={{ .Commit }} -X github.com/localstack/lstk/internal/version.buildDate={{ .Date }}
- -s -w -X github.com/localstack/lstk/internal/version.version={{ .Version }}

archives:
- id: lstk
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ lstk update
# Show resolved config file path
lstk config path

# Show version info
lstk version
```

## Reporting bugs
Expand Down
1 change: 1 addition & 0 deletions cmd/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestRootHelpOutputTemplate(t *testing.T) {
assertContains(t, out, "Options:")
assertNotContains(t, out, "Available Commands:")
assertNotContains(t, out, `Use "lstk [command] --help" for more information about a command.`)
assertNotContains(t, out, "\n version ")
}

func TestSubcommandHelpUsesSubcommandUsageLine(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/non_interactive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestNonInteractiveFlagAppearsInStopHelp(t *testing.T) {
func TestNonInteractiveFlagBindsToCfg(t *testing.T) {
cfg := &env.Env{}
root := NewRootCmd(cfg, telemetry.New("", true), log.Nop())
root.SetArgs([]string{"--non-interactive", "version"})
root.SetArgs([]string{"--non-interactive", "--version"})
_ = root.Execute()

if !cfg.NonInteractive {
Expand All @@ -59,7 +59,7 @@ func TestNonInteractiveFlagBindsToCfg(t *testing.T) {
func TestNonInteractiveFlagDefaultIsOff(t *testing.T) {
cfg := &env.Env{}
root := NewRootCmd(cfg, telemetry.New("", true), log.Nop())
root.SetArgs([]string{"version"})
root.SetArgs([]string{"--version"})
_ = root.Execute()

if cfg.NonInteractive {
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra.C
}

root.Version = version.Version()
root.SetVersionTemplate(versionLine() + "\n")
root.SilenceErrors = true
root.SilenceUsage = true

Expand All @@ -45,7 +44,9 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra.C
configureHelp(root)

root.InitDefaultVersionFlag()
root.Flags().Lookup("version").Shorthand = "v"
root.Flags().Lookup("version").Usage = "Show version"
root.SetVersionTemplate(versionLine() + "\n")

root.AddCommand(
newStartCmd(cfg, tel, logger),
Expand All @@ -55,7 +56,6 @@ func NewRootCmd(cfg *env.Env, tel *telemetry.Client, logger log.Logger) *cobra.C
newStatusCmd(cfg),
newLogsCmd(),
newConfigCmd(),
newVersionCmd(),
newUpdateCmd(cfg),
)

Expand Down
15 changes: 1 addition & 14 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,8 @@ import (
"fmt"

"github.com/localstack/lstk/internal/version"
"github.com/spf13/cobra"
)

func newVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Show version",
Long: "Print version information for the lstk binary.",
RunE: func(cmd *cobra.Command, args []string) error {
_, err := fmt.Fprintln(cmd.OutOrStdout(), versionLine())
return err
},
}
}

func versionLine() string {
return fmt.Sprintf("lstk %s (%s, %s)", version.Version(), version.Commit(), version.BuildDate())
return fmt.Sprintf("lstk %s", version.Version())
}
30 changes: 22 additions & 8 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
package cmd

import (
"strings"
"testing"
)
import "testing"

func TestVersionLine(t *testing.T) {
got := versionLine()

if !strings.HasPrefix(got, "lstk ") {
t.Fatalf("versionLine() = %q, should start with 'lstk '", got)
if got != "lstk dev" {
t.Fatalf("versionLine() = %q, want %q", got, "lstk dev")
}
if !strings.Contains(got, "(") || !strings.Contains(got, ")") {
t.Fatalf("versionLine() = %q, should contain parentheses with commit and date", got)
}

func TestVersionFlagsPrintSameOutput(t *testing.T) {
longOut, err := executeWithArgs(t, "--version")
if err != nil {
t.Fatalf("expected no error from --version, got %v", err)
}

shortOut, err := executeWithArgs(t, "-v")
if err != nil {
t.Fatalf("expected no error from -v, got %v", err)
}

want := versionLine() + "\n"
if longOut != want {
t.Fatalf("--version output = %q, want %q", longOut, want)
}
if shortOut != longOut {
t.Fatalf("-v output = %q, want %q", shortOut, longOut)
}
}
12 changes: 3 additions & 9 deletions internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package version

// Set via ldflags at build time. Must be variables, not constants,
// Set via ldflags at build time. Must be a variable, not a constant,
// because the linker can only modify variables at link time.
var (
version = "dev"
commit = "none"
buildDate = "unknown"
)
var version = "dev"

func Version() string { return version }
func Commit() string { return commit }
func BuildDate() string { return buildDate }
func Version() string { return version }
4 changes: 2 additions & 2 deletions test/integration/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestLogging_NonTTY_WritesToLogFile(t *testing.T) {
_ = os.Remove(logPath)

ctx := testContext(t)
_, _, err := runLstk(t, ctx, "", nil, "version")
_, _, err := runLstk(t, ctx, "", nil, "--version")
require.NoError(t, err)

logContents, err := os.ReadFile(logPath)
Expand All @@ -28,7 +28,7 @@ func TestLogging_TTY_WritesToLogFile(t *testing.T) {
_ = os.Remove(logPath)

ctx := testContext(t)
_, err := runLstkInPTY(t, ctx, nil, "version")
_, err := runLstkInPTY(t, ctx, nil, "--version")
require.NoError(t, err)

logContents, err := os.ReadFile(logPath)
Expand Down
5 changes: 2 additions & 3 deletions test/integration/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ func TestDeviceFlowSuccess(t *testing.T) {
cleanup()
t.Cleanup(cleanup)

// Require valid token from environment
licenseToken := env.Require(t, env.AuthToken)
licenseToken := "test-license-token"

// Create mock API server that returns the real token
// Create mock API server that returns a synthetic token
mockServer := createMockAPIServer(t, licenseToken, true)
defer mockServer.Close()

Expand Down
6 changes: 3 additions & 3 deletions test/integration/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestUpdateBinaryInPlace(t *testing.T) {
require.NoError(t, err, "go build failed: %s", string(out))

// Verify it reports the fake version
verCmd := exec.CommandContext(ctx, tmpBinary, "version")
verCmd := exec.CommandContext(ctx, tmpBinary, "--version")
verOut, err := verCmd.CombinedOutput()
require.NoError(t, err)
assert.Contains(t, string(verOut), "0.0.1")
Expand All @@ -136,7 +136,7 @@ func TestUpdateBinaryInPlace(t *testing.T) {
assert.Contains(t, updateStr, "Updated to", "should complete the update")

// Verify the binary was actually replaced
verCmd2 := exec.CommandContext(ctx, tmpBinary, "version")
verCmd2 := exec.CommandContext(ctx, tmpBinary, "--version")
verOut2, err := verCmd2.CombinedOutput()
require.NoError(t, err)
assert.NotContains(t, string(verOut2), "0.0.1", "binary should no longer be the old version")
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestUpdateHomebrew(t *testing.T) {
require.NoError(t, err, "go build failed: %s", string(out))

// Verify it reports the fake version
verCmd := exec.CommandContext(ctx, caskBinary, "version")
verCmd := exec.CommandContext(ctx, caskBinary, "--version")
verOut, err := verCmd.CombinedOutput()
require.NoError(t, err)
assert.Contains(t, string(verOut), "0.0.1")
Expand Down
Loading