update cmd/root.go

master
taoshihan 1 month ago
parent cbb19ba5c1
commit b88458af24

@ -3,9 +3,8 @@ package cmd
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"os"
) )
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@ -36,5 +35,4 @@ func init() {
// Original command adding logic preserved // Original command adding logic preserved
rootCmd.AddCommand(serverCmd) rootCmd.AddCommand(serverCmd)
rootCmd.AddCommand(installCmd) rootCmd.AddCommand(installCmd)
rootCmd.AddCommand(stopCmd)
} }

@ -1,30 +0,0 @@
package cmd
import (
"github.com/spf13/cobra"
"io/ioutil"
"os/exec"
"runtime"
"strings"
)
var stopCmd = &cobra.Command{
Use: "stop",
Short: "停止http服务",
Run: func(cmd *cobra.Command, args []string) {
pids, err := ioutil.ReadFile("gofly.sock")
if err != nil {
return
}
pidSlice := strings.Split(string(pids), ",")
var command *exec.Cmd
for _, pid := range pidSlice {
if runtime.GOOS == "windows" {
command = exec.Command("taskkill.exe", "/f", "/pid", pid)
} else {
command = exec.Command("kill", pid)
}
command.Start()
}
},
}
Loading…
Cancel
Save