update command

pull/746/head
hunterlong 2020-07-14 13:32:31 -07:00
parent 482c32fe11
commit eb98632f1d
2 changed files with 43 additions and 0 deletions

View File

@ -1,10 +1,13 @@
package main
import (
"bytes"
"fmt"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"io"
"os"
"os/exec"
)
var rootCmd = &cobra.Command{
@ -15,6 +18,45 @@ var rootCmd = &cobra.Command{
},
}
var updateCmd = &cobra.Command{
Use: "update",
Short: "Update to the latest version",
RunE: func(cmd *cobra.Command, args []string) error {
log.Infoln("Updating Statping to the latest version...")
curl, err := exec.LookPath("curl")
if err != nil {
return err
}
bash, err := exec.LookPath("bash")
if err != nil {
return err
}
ree := bytes.NewBuffer(nil)
c1 := exec.Command(curl, "-o-", "-L", "https://statping.com/install.sh")
c2 := exec.Command(bash)
r, w := io.Pipe()
c1.Stdout = w
c2.Stdin = r
var b2 bytes.Buffer
c2.Stdout = &b2
c1.Start()
c2.Start()
c1.Wait()
w.Close()
c2.Wait()
io.Copy(ree, &b2)
log.Infoln(ree.String())
os.Exit(0)
return nil
},
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Statping",

View File

@ -33,6 +33,7 @@ func init() {
utils.InitEnvs()
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(updateCmd)
rootCmd.AddCommand(assetsCmd)
rootCmd.AddCommand(exportCmd)
rootCmd.AddCommand(importCmd)