重构架构

This commit is contained in:
2026-02-20 18:44:43 +08:00
parent aba7b68439
commit cc71248ef4
52 changed files with 1404 additions and 2360 deletions

46
internal/cli/init/cfg.go Normal file
View File

@@ -0,0 +1,46 @@
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
)
cmd := &cobra.Command{
Use: "config",
Short: "生成默认配置文件",
Long: `
在指定路径生成 SunHPC 默认配置文件 (sunhpc.yaml)
示例:
sunhpc init config # 生成默认配置文件
sunhpc init config -f # 强制覆盖已有配置文件
sunhpc init config -p /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, "显示详细日志")
return cmd
}