diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md index 7d9641c3..1e233b10 100644 --- a/docs/docs/changelog.md +++ b/docs/docs/changelog.md @@ -5,6 +5,7 @@ title: Changelog ## [Unreleased](https://github.com/lets-cli/lets/releases/tag/v0.0.X) +* `[Added]` Add `update` as an alias for `lets self upgrade`. * `[Added]` Add `checksum.files`, `checksum.sh`, and `checksum.persist` command checksum syntax while keeping the old checksum format compatible. * `[Added]` Add `lets self upgrade --pre` to opt into upgrading to the latest prerelease. * `[Added]` Add `lets self fix` config migration command with `--dry-run` preview output for deprecated checksum syntax. diff --git a/internal/cmd/root_test.go b/internal/cmd/root_test.go index 3a2650ae..c510de29 100644 --- a/internal/cmd/root_test.go +++ b/internal/cmd/root_test.go @@ -418,37 +418,39 @@ func TestSelfCmd(t *testing.T) { } }) - t.Run("should run self upgrade subcommand", func(t *testing.T) { - bufOut := new(bytes.Buffer) - called := false + for _, command := range []string{"upgrade", "update"} { + t.Run("should run self "+command+" subcommand", func(t *testing.T) { + bufOut := new(bytes.Buffer) + called := false + + rootCmd := CreateRootCommand("v0.0.0-test", "") + rootCmd.SetArgs([]string{"self", command}) + rootCmd.SetOut(bufOut) + rootCmd.SetErr(bufOut) + selfCmd := &cobra.Command{ + Use: "self", + Short: "Manage lets CLI itself", + } + rootCmd.AddCommand(selfCmd) - rootCmd := CreateRootCommand("v0.0.0-test", "") - rootCmd.SetArgs([]string{"self", "upgrade"}) - rootCmd.SetOut(bufOut) - rootCmd.SetErr(bufOut) - selfCmd := &cobra.Command{ - Use: "self", - Short: "Manage lets CLI itself", - } - rootCmd.AddCommand(selfCmd) + selfCmd.AddCommand(initUpgradeCommandWith(func(_ *cobra.Command) (upgrade.Upgrader, error) { + return mockUpgraderFunc(func(ctx context.Context) error { + called = true - selfCmd.AddCommand(initUpgradeCommandWith(func(_ *cobra.Command) (upgrade.Upgrader, error) { - return mockUpgraderFunc(func(ctx context.Context) error { - called = true + return nil + }), nil + })) - return nil - }), nil - })) - - err := rootCmd.Execute() - if err != nil { - t.Fatalf("unexpected error: %v", err) - } + err := rootCmd.Execute() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } - if !called { - t.Fatal("expected upgrader to be called") - } - }) + if !called { + t.Fatal("expected upgrader to be called") + } + }) + } t.Run("should pass pre flag to self upgrade factory", func(t *testing.T) { bufOut := new(bytes.Buffer) diff --git a/internal/cmd/upgrade.go b/internal/cmd/upgrade.go index 51b2347b..5f0b3e07 100644 --- a/internal/cmd/upgrade.go +++ b/internal/cmd/upgrade.go @@ -49,9 +49,10 @@ func upgradeProgress(stderr io.Writer, appSettings settings.Settings) fetch.Prog func initUpgradeCommandWith(createUpgrader upgraderFactory) *cobra.Command { upgradeCmd := &cobra.Command{ - Use: "upgrade", - Short: "Upgrade lets to latest version", - Args: cobra.NoArgs, + Use: "upgrade", + Aliases: []string{"update"}, + Short: "Upgrade lets to latest version", + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { upgrader, err := createUpgrader(cmd) if err != nil {