magic/cmd/nginx/read.go
2026-03-28 19:25:12 +08:00

47 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package nginx
import (
"context"
"fmt"
"strings"
"gitea.micah.wiki/pandora/naive/pkg/stdinx"
"gitea.micah.wiki/pandora/magic/config"
)
//func ReadIsNew(ctx context.Context) (bool, error) {
// isNewFlag, err := stdinx.ReadStr(ctx, fmt.Sprintf("*** 新增 or 更新:(新增: Y; 更新: N;"))
// if err != nil {
// return false, err
// }
//
// if strings.EqualFold(isNewFlag, "y") {
// return true, nil
// }
//
// return false, nil
//}
func ReadCurrent(ctx context.Context, conf *config.Config) (*config.Nginx, error) {
total := len(conf.Nginx)
for i, nginx := range conf.Nginx {
check, err := stdinx.ReadStr(ctx, fmt.Sprintf("*** 请确认是否需要生成当前域名`%s`(%d/%d):(是: Y; 否: N;", nginx.Domain, i+1, total))
if err != nil {
return nil, err
}
if strings.EqualFold(check, "y") {
return nginx, nil
}
}
return nil, fmt.Errorf("未选择任何需要生成的域名,请编辑配置后,再运行")
}
func ReadRestart(ctx context.Context) bool {
restartFlag, err := stdinx.ReadStr(ctx, "*** 是否需要重启nginx确认Y or Yes按其他任意键不重启")
if err != nil {
return false
}
return strings.EqualFold(restartFlag, "yes") || strings.EqualFold(restartFlag, "y")
}