projectx/cmd/root.go
2025-05-07 14:12:53 +08:00

49 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"os"
"github.com/spf13/cobra"
)
// rootCmd 表示在没有任何子命令的情况下调用的基本命令
var rootCmd = &cobra.Command{
Use: "management",
Short: "ERP 管理系统命令行工具",
Long: `ERP 管理系统命令行工具,用于管理和控制 ERP 管理服务器。支持多种操作,如启动服务器、根据不同配置文件加载服务等。
示例:
# 使用默认配置文件启动 ERP 管理服务器
./management erp
# 使用自定义配置文件启动 ERP 管理服务器
./management erp -c config.prod.yaml
该工具依赖 Cobra 库构建,在 Windows 系统上使用标准的 http.Server 启动服务,其他系统使用 endless 库实现热重启。
`,
// 如果您的裸应用程序没有注释以下行
// 具有与之关联的操作:
// Run: func(cmd *cobra.Command, args []string) { },
}
// Execute 将所有子命令添加到根命令中,并相应地设置标志。
// 这是由main.main调用的。rootCmd只需要发生一次。
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
// 在这里,您将定义您的标志和配置设置。
// Cobra支持持久标志如果在这里定义
// 将为您的应用程序提供全球支持。
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.management.yaml)")
// Cobra还支持仅运行本地标志
// 当直接调用此操作时。
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}