github.com/fozzysec/SiaPrime@v0.0.0-20190612043147-66c8e8d11fe3/cmd/spc/daemoncmd.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 "SiaPrime/build" 8 ) 9 10 var ( 11 stopCmd = &cobra.Command{ 12 Use: "stop", 13 Short: "Stop the SiaPrime daemon", 14 Long: "Stop the SiaPrime daemon.", 15 Run: wrap(stopcmd), 16 } 17 18 updateCheckCmd = &cobra.Command{ 19 Use: "check", 20 Short: "Check for available updates", 21 Long: "Check for available updates.", 22 Run: wrap(updatecheckcmd), 23 } 24 25 updateCmd = &cobra.Command{ 26 Use: "update", 27 Short: "Update SiaPrime", 28 Long: "Check for (and/or download) available updates for SiaPrime.", 29 Run: wrap(updatecmd), 30 } 31 32 versionCmd = &cobra.Command{ 33 Use: "version", 34 Short: "Print version information", 35 Long: "Print version information.", 36 Run: wrap(versioncmd), 37 } 38 ) 39 40 // version prints the version of siac and siad. 41 func versioncmd() { 42 fmt.Println("SiaPrime Client") 43 if build.ReleaseTag == "" { 44 fmt.Println("\tVersion " + build.Version) 45 } else { 46 fmt.Println("\tVersion " + build.Version + "-" + build.ReleaseTag) 47 } 48 if build.GitRevision != "" { 49 fmt.Println("\tGit Revision " + build.GitRevision) 50 fmt.Println("\tBuild Time " + build.BuildTime) 51 } 52 dvg, err := httpClient.DaemonVersionGet() 53 if err != nil { 54 fmt.Println("Could not get daemon version:", err) 55 return 56 } 57 fmt.Println("SiaPrime Daemon") 58 fmt.Println("\tVersion " + dvg.Version) 59 if build.GitRevision != "" { 60 fmt.Println("\tGit Revision " + dvg.GitRevision) 61 fmt.Println("\tBuild Time " + dvg.BuildTime) 62 } 63 } 64 65 // stopcmd is the handler for the command `siac stop`. 66 // Stops the daemon. 67 func stopcmd() { 68 err := httpClient.DaemonStopGet() 69 if err != nil { 70 die("Could not stop daemon:", err) 71 } 72 fmt.Println("SiaPrime daemon stopped.") 73 } 74 75 func updatecmd() { 76 update, err := httpClient.DaemonUpdateGet() 77 if err != nil { 78 fmt.Println("Could not check for update:", err) 79 return 80 } 81 if !update.Available { 82 fmt.Println("Already up to date.") 83 return 84 } 85 86 err = httpClient.DaemonUpdatePost() 87 if err != nil { 88 fmt.Println("Could not apply update:", err) 89 return 90 } 91 fmt.Printf("Updated to version %s! Restart spd now.\n", update.Version) 92 } 93 94 func updatecheckcmd() { 95 update, err := httpClient.DaemonUpdateGet() 96 if err != nil { 97 fmt.Println("Could not check for update:", err) 98 return 99 } 100 if update.Available { 101 fmt.Printf("A new release (v%s) is available! Run 'spc update' to install it.\n", update.Version) 102 } else { 103 fmt.Println("Up to date.") 104 } 105 }