Tui 重构代码逻辑

This commit is contained in:
2026-02-27 22:52:15 +08:00
parent 3a5f5ddd5d
commit d4e214fe23
8 changed files with 934 additions and 718 deletions

View File

@@ -2,20 +2,12 @@ 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())
@@ -27,20 +19,3 @@ func Run(force bool) error {
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
}