Files
sunhpc-go/internal/cli/init/cfg.go

39 lines
749 B
Go
Raw Normal View History

2026-02-14 05:36:00 +08:00
package initcmd
import (
2026-02-20 18:44:43 +08:00
"sunhpc/internal/middler/auth"
2026-02-14 05:36:00 +08:00
"github.com/spf13/cobra"
)
2026-02-15 07:18:14 +08:00
// NewConfigCmd 创建 "init config" 命令
2026-02-20 18:44:43 +08:00
func NewInitCfgCmd() *cobra.Command {
2026-02-15 07:18:14 +08:00
var (
2026-02-20 20:24:02 +08:00
output string
2026-02-15 07:18:14 +08:00
)
cmd := &cobra.Command{
Use: "config",
Short: "生成默认配置文件",
Long: `
在指定路径生成 SunHPC 默认配置文件 (sunhpc.yaml)
示例:
sunhpc init config # 生成默认配置文件
2026-02-20 20:24:02 +08:00
sunhpc init config -o /etc/sunhpc/sunhpc.yaml # 指定路径
2026-02-15 07:18:14 +08:00
`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := auth.RequireRoot(); err != nil {
return err
}
2026-02-14 05:36:00 +08:00
2026-02-15 07:18:14 +08:00
return nil
},
}
2026-02-14 05:36:00 +08:00
2026-02-15 07:18:14 +08:00
// 定义局部 flags
2026-02-20 20:24:02 +08:00
cmd.Flags().StringVarP(&output, "output", "o", "", "指定配置文件路径")
2026-02-14 05:36:00 +08:00
2026-02-15 07:18:14 +08:00
return cmd
2026-02-14 05:36:00 +08:00
}