Skip to content

Commit

Permalink
add upgrade command
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsdev0 committed Jul 12, 2024
1 parent 51e8510 commit b6c31f9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
39 changes: 39 additions & 0 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cmd

import (
"fmt"
"os/exec"
"regexp"

"github.com/bootdotdev/bootdev/version"
"github.com/spf13/cobra"
)

var upgradeCmd = &cobra.Command{
Use: "upgrade",
Aliases: []string{"update"},
Short: "Installs the latest version of the CLI.",
Run: func(cmd *cobra.Command, args []string) {
info := version.FromContext(cmd.Context())
if !info.IsOutdated {
fmt.Println("Boot.dev CLI is already up to date.")
return
}
// install the latest version
command := exec.Command("go", "install", "github.com/bootdotdev/bootdev@latest")
b, err := command.Output()
cobra.CheckErr(err)

// Get the new version info
command = exec.Command("bootdev", "--version")
b, err = command.Output()
cobra.CheckErr(err)
re := regexp.MustCompile(`v\d+\.\d+\.\d+`)
version := re.FindString(string(b))
fmt.Printf("Successfully upgraded to %s!\n", version)
},
}

func init() {
rootCmd.AddCommand(upgradeCmd)
}
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.6.0
v1.6.1
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (v *VersionInfo) PromptUpdateIfAvailable() {
if v.IsOutdated {
fmt.Fprintln(os.Stderr, "A new version of the bootdev CLI is available!")
fmt.Fprintln(os.Stderr, "Please run the following command to update:")
fmt.Fprintf(os.Stderr, " go install github.com/%s/%s@latest\n\n", repoOwner, repoName)
fmt.Fprintf(os.Stderr, " bootdev upgrade\n\n")
}
}

Expand Down

0 comments on commit b6c31f9

Please sign in to comment.