Forráskód Böngészése

更新根命令检测逻辑

修改了控制台模式的检测逻辑,使其在非Windows系统上默认启用控制台,并仅在Windows系统上检查是否实际存在控制台窗口。
SongZihuan 1 hete
szülő
commit
13f237652b
1 módosított fájl, 7 hozzáadás és 2 törlés
  1. 7 2
      src/cmdparser/root/root.go

+ 7 - 2
src/cmdparser/root/root.go

@@ -12,6 +12,7 @@ import (
 	"github.com/SongZihuan/BackendServerTemplate/src/utils/cleanstringutils"
 	"github.com/SongZihuan/BackendServerTemplate/src/utils/consoleutils"
 	"github.com/spf13/cobra"
+	"runtime"
 )
 
 const (
@@ -26,7 +27,11 @@ var consoleMode string = ConsoleModeNormal
 var hasConsole bool = false
 
 func GetRootCMD(shortDescribe string, longDescribe string, reload *bool, _hasConsole bool, action func(cmd *cobra.Command, args []string) error) *cobra.Command {
-	hasConsole = _hasConsole && consoleutils.HasConsoleWindow()
+	if runtime.GOOS == "windows" {
+		hasConsole = _hasConsole && consoleutils.HasConsoleWindow()
+	} else {
+		hasConsole = true
+	}
 
 	cmd := &cobra.Command{
 		Use:           global.Name,
@@ -106,7 +111,7 @@ func GetRootCMD(shortDescribe string, longDescribe string, reload *bool, _hasCon
 
 	cmd.PersistentFlags().StringVarP(&name, "name", "n", global.Name, "the program display name")
 
-	if _hasConsole {
+	if _hasConsole && runtime.GOOS == "windows" {
 		cmd.Flags().StringVar(&consoleMode, "console-mode", ConsoleModeNormal, "the console mode. normally, select `normal`. If you are not using a terminal (e.g. redirection, etc.) please select `no`.")
 	}