mirror of https://github.com/statping/statping
update command
parent
482c32fe11
commit
eb98632f1d
|
@ -1,10 +1,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
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{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the version number of Statping",
|
Short: "Print the version number of Statping",
|
||||||
|
|
|
@ -33,6 +33,7 @@ func init() {
|
||||||
utils.InitEnvs()
|
utils.InitEnvs()
|
||||||
|
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
rootCmd.AddCommand(updateCmd)
|
||||||
rootCmd.AddCommand(assetsCmd)
|
rootCmd.AddCommand(assetsCmd)
|
||||||
rootCmd.AddCommand(exportCmd)
|
rootCmd.AddCommand(exportCmd)
|
||||||
rootCmd.AddCommand(importCmd)
|
rootCmd.AddCommand(importCmd)
|
||||||
|
|
Loading…
Reference in New Issue