55 "fmt"
66 "os"
77 "os/exec"
8- "path/filepath"
98 "runtime"
109 "strings"
1110 "time"
@@ -15,22 +14,12 @@ import (
1514 "github.com/spf13/cobra"
1615)
1716
18- // InstallMethod represents how kernel was installed
19- type InstallMethod string
20-
21- const (
22- InstallMethodBrew InstallMethod = "brew"
23- InstallMethodPNPM InstallMethod = "pnpm"
24- InstallMethodNPM InstallMethod = "npm"
25- InstallMethodBun InstallMethod = "bun"
26- InstallMethodUnknown InstallMethod = "unknown"
27- )
28-
2917var dryRun bool
3018
3119var upgradeCmd = & cobra.Command {
32- Use : "upgrade" ,
33- Short : "Upgrade the Kernel CLI to the latest version" ,
20+ Use : "upgrade" ,
21+ Aliases : []string {"update" },
22+ Short : "Upgrade the Kernel CLI to the latest version" ,
3423 Long : `Upgrade the Kernel CLI to the latest version.
3524
3625Supported installation methods:
@@ -56,7 +45,7 @@ func runUpgrade(cmd *cobra.Command, args []string) error {
5645
5746 pterm .Info .Println ("Checking for updates..." )
5847
59- latestTag , _ , err := update .FetchLatest (ctx )
48+ latestTag , releaseURL , err := update .FetchLatest (ctx )
6049 if err != nil {
6150 return fmt .Errorf ("failed to check for updates: %w" , err )
6251 }
@@ -68,16 +57,19 @@ func runUpgrade(cmd *cobra.Command, args []string) error {
6857 pterm .Warning .Printf ("Could not compare versions (%s vs %s): %v\n " , currentVersion , latestTag , err )
6958 pterm .Info .Println ("Proceeding with upgrade..." )
7059 } else if ! isNewer {
71- pterm .Success .Printf ("You are already on the latest version (%s)\n " , currentVersion )
60+ pterm .Success .Printf ("You are already on the latest version (%s)\n " , strings . TrimPrefix ( currentVersion , "v" ) )
7261 return nil
7362 } else {
74- pterm .Info .Printf ("New version available: %s → %s\n " , currentVersion , strings .TrimPrefix (latestTag , "v" ))
63+ pterm .Info .Printf ("New version available: %s → %s\n " , strings .TrimPrefix (currentVersion , "v" ), strings .TrimPrefix (latestTag , "v" ))
64+ if releaseURL != "" {
65+ pterm .Info .Printf ("Release notes: %s\n " , releaseURL )
66+ }
7567 }
7668
7769 // Detect installation method
78- method , binaryPath := DetectInstallMethod ()
70+ method , binaryPath := update . DetectInstallMethod ()
7971
80- if method == InstallMethodUnknown {
72+ if method == update . InstallMethodUnknown {
8173 printManualUpgradeInstructions (latestTag , binaryPath )
8274 return fmt .Errorf ("could not detect installation method" )
8375 }
@@ -91,114 +83,34 @@ func runUpgrade(cmd *cobra.Command, args []string) error {
9183 return executeUpgrade (method )
9284}
9385
94- // DetectInstallMethod detects how kernel was installed and returns the method
95- // along with the path to the kernel binary.
96- func DetectInstallMethod () (InstallMethod , string ) {
97- // Collect candidate paths: current executable and shell-resolved binary
98- candidates := []string {}
99- binaryPath := ""
100-
101- if exe , err := os .Executable (); err == nil && exe != "" {
102- if real , err2 := filepath .EvalSymlinks (exe ); err2 == nil && real != "" {
103- exe = real
104- }
105- candidates = append (candidates , exe )
106- binaryPath = exe
107- }
108- if which , err := exec .LookPath ("kernel" ); err == nil && which != "" {
109- candidates = append (candidates , which )
110- if binaryPath == "" {
111- binaryPath = which
112- }
113- }
114-
115- // Helpers
116- norm := func (p string ) string { return strings .ToLower (filepath .ToSlash (p )) }
117- hasHomebrew := func (p string ) bool {
118- p = norm (p )
119- return strings .Contains (p , "homebrew" ) || strings .Contains (p , "/cellar/" )
120- }
121- hasBun := func (p string ) bool { p = norm (p ); return strings .Contains (p , "/.bun/" ) }
122- hasPNPM := func (p string ) bool {
123- p = norm (p )
124- return strings .Contains (p , "/pnpm/" ) || strings .Contains (p , "/.pnpm/" )
125- }
126- hasNPM := func (p string ) bool {
127- p = norm (p )
128- return strings .Contains (p , "/npm/" ) || strings .Contains (p , "/node_modules/.bin/" )
129- }
130-
131- type rule struct {
132- check func (string ) bool
133- envKeys []string
134- method InstallMethod
135- }
136-
137- rules := []rule {
138- {hasHomebrew , nil , InstallMethodBrew },
139- {hasBun , []string {"BUN_INSTALL" }, InstallMethodBun },
140- {hasPNPM , []string {"PNPM_HOME" }, InstallMethodPNPM },
141- {hasNPM , []string {"NPM_CONFIG_PREFIX" , "npm_config_prefix" , "VOLTA_HOME" }, InstallMethodNPM },
142- }
143-
144- // Path-based detection first
145- for _ , c := range candidates {
146- for _ , r := range rules {
147- if r .check != nil && r .check (c ) {
148- return r .method , binaryPath
149- }
150- }
151- }
152-
153- // Env-only fallbacks
154- envSet := func (keys []string ) bool {
155- for _ , k := range keys {
156- if k == "" {
157- continue
158- }
159- if os .Getenv (k ) != "" {
160- return true
161- }
162- }
163- return false
164- }
165- for _ , r := range rules {
166- if len (r .envKeys ) > 0 && envSet (r .envKeys ) {
167- return r .method , binaryPath
168- }
169- }
170-
171- return InstallMethodUnknown , binaryPath
172- }
173-
17486// getUpgradeCommand returns the command string for a given installation method
175- func getUpgradeCommand (method InstallMethod ) string {
87+ func getUpgradeCommand (method update. InstallMethod ) string {
17688 switch method {
177- case InstallMethodBrew :
89+ case update . InstallMethodBrew :
17890 return "brew upgrade kernel/tap/kernel"
179- case InstallMethodPNPM :
91+ case update . InstallMethodPNPM :
18092 return "pnpm add -g @onkernel/cli@latest"
181- case InstallMethodNPM :
93+ case update . InstallMethodNPM :
18294 return "npm i -g @onkernel/cli@latest"
183- case InstallMethodBun :
95+ case update . InstallMethodBun :
18496 return "bun add -g @onkernel/cli@latest"
18597 default :
18698 return ""
18799 }
188100}
189101
190102// executeUpgrade runs the appropriate upgrade command based on the installation method
191- func executeUpgrade (method InstallMethod ) error {
103+ func executeUpgrade (method update. InstallMethod ) error {
192104 var cmd * exec.Cmd
193105
194106 switch method {
195- case InstallMethodBrew :
107+ case update . InstallMethodBrew :
196108 cmd = exec .Command ("brew" , "upgrade" , "kernel/tap/kernel" )
197- case InstallMethodPNPM :
109+ case update . InstallMethodPNPM :
198110 cmd = exec .Command ("pnpm" , "add" , "-g" , "@onkernel/cli@latest" )
199- case InstallMethodNPM :
111+ case update . InstallMethodNPM :
200112 cmd = exec .Command ("npm" , "i" , "-g" , "@onkernel/cli@latest" )
201- case InstallMethodBun :
113+ case update . InstallMethodBun :
202114 cmd = exec .Command ("bun" , "add" , "-g" , "@onkernel/cli@latest" )
203115 default :
204116 return fmt .Errorf ("unknown installation method" )
0 commit comments