39 lines
749 B
Go
39 lines
749 B
Go
package initcmd
|
|
|
|
import (
|
|
"sunhpc/internal/middler/auth"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// NewConfigCmd 创建 "init config" 命令
|
|
func NewInitCfgCmd() *cobra.Command {
|
|
var (
|
|
output string
|
|
)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "config",
|
|
Short: "生成默认配置文件",
|
|
Long: `
|
|
在指定路径生成 SunHPC 默认配置文件 (sunhpc.yaml)
|
|
|
|
示例:
|
|
sunhpc init config # 生成默认配置文件
|
|
sunhpc init config -o /etc/sunhpc/sunhpc.yaml # 指定路径
|
|
`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := auth.RequireRoot(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// 定义局部 flags
|
|
cmd.Flags().StringVarP(&output, "output", "o", "", "指定配置文件路径")
|
|
|
|
return cmd
|
|
}
|