47 lines
965 B
Go
47 lines
965 B
Go
package wizard
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
)
|
|
|
|
// Run 启动初始化向导
|
|
func Run(force bool) error {
|
|
// 检查是否已有配置
|
|
if !force && ConfigExists() {
|
|
fmt.Println("⚠️ 检测到已有配置文件")
|
|
fmt.Println(" 使用 --force 参数强制重新初始化")
|
|
fmt.Println(" 或运行 sunhpc init tui --force")
|
|
return nil
|
|
}
|
|
|
|
// 创建程序实例
|
|
p := tea.NewProgram(initialModel())
|
|
|
|
// 运行程序
|
|
if _, err := p.Run(); err != nil {
|
|
return fmt.Errorf("初始化向导运行失败:%w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// getConfigPath 获取配置文件路径
|
|
func GetConfigPath() string {
|
|
// 优先使用环境变量
|
|
if path := os.Getenv("SUNHPC_CONFIG"); path != "" {
|
|
return path
|
|
}
|
|
// 默认路径
|
|
return "/etc/sunhpc/config.json"
|
|
}
|
|
|
|
// configExists 检查配置文件是否存在
|
|
func ConfigExists() bool {
|
|
configPath := GetConfigPath()
|
|
_, err := os.Stat(configPath)
|
|
return err == nil
|
|
}
|