add config.yaml

This commit is contained in:
2026-02-20 20:24:02 +08:00
parent a3917c5a15
commit fbe6aec707
5 changed files with 516 additions and 135 deletions

View File

@@ -2,18 +2,14 @@ package initcmd
import (
"sunhpc/internal/middler/auth"
"sunhpc/pkg/logger"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
// NewConfigCmd 创建 "init config" 命令
func NewInitCfgCmd() *cobra.Command {
var (
force bool
path string
verbose bool
output string
)
cmd := &cobra.Command{
@@ -24,23 +20,19 @@ func NewInitCfgCmd() *cobra.Command {
示例:
sunhpc init config # 生成默认配置文件
sunhpc init config -f # 强制覆盖已有配置文件
sunhpc init config -p /etc/sunhpc/sunhpc.yaml # 指定路径
sunhpc init config -o /etc/sunhpc/sunhpc.yaml # 指定路径
`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := auth.RequireRoot(); err != nil {
return err
}
logger.Info("✅ 配置文件已生成", zap.String("path", path))
return nil
},
}
// 定义局部 flags
cmd.Flags().BoolVarP(&force, "force", "f", false, "强制覆盖已有配置文件")
cmd.Flags().StringVarP(&path, "path", "p", "", "指定配置文件路径")
cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "显示详细日志")
cmd.Flags().StringVarP(&output, "output", "o", "", "指定配置文件路径")
return cmd
}