/ cmd / update.go
update.go
 1  package cmd
 2  
 3  import (
 4  	"fmt"
 5  
 6  	"github.com/spf13/cobra"
 7  
 8  	"github.com/Kocoro-lab/ShanClaw/internal/update"
 9  )
10  
11  var updateCmd = &cobra.Command{
12  	Use:   "update",
13  	Short: "Update shan to the latest version",
14  	RunE: func(cmd *cobra.Command, args []string) error {
15  		fmt.Printf("shan %s (%s)\n", Version, update.PlatformInfo())
16  		fmt.Println("Checking for updates...")
17  
18  		newVersion, err := update.DoUpdate(Version)
19  		if err != nil {
20  			return fmt.Errorf("%v", err)
21  		}
22  		fmt.Printf("Updated to v%s. Restart to use new version.\n", newVersion)
23  		return nil
24  	},
25  }
26  
27  func init() {
28  	rootCmd.AddCommand(updateCmd)
29  }