Fetch the repository succeeded.
package yscmd
import (
"fmt"
"gitee.com/kmyss/gf-ex/yslog"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
)
func ScanAndLog(info ...interface{}) string {
r := gcmd.Scan(info...)
out := fmt.Sprint(info...) + r
yslog.PrintToFile(out)
return r
}
// ScanWithDefault 获取输入参数和默认值
// Deprecated: 这个函数将在下一个版本更新时弃用, 新函数是 ScanWithDefaultN
func ScanWithDefault(defaultValue string, info string) string {
r := ScanAndLog(fmt.Sprintf("%s[默认值:%s]", info, defaultValue))
switch r {
case "":
return defaultValue
default:
return r
}
}
// ScanWithDefaultN 获取输入参数和默认值, 调整参数顺序
func ScanWithDefaultN(info string, defaultValue string) string {
r := ScanAndLog(fmt.Sprintf("%s[默认值:%s]", info, defaultValue))
switch r {
case "":
return defaultValue
default:
return r
}
}
// ScanYesOrNo 选择 yes 或者 no
// 默认值通过 <defaultValue> 设置,默认为 y 在特殊情况时可以自己设置为 n
// 输入 y 返回 True. 输入 n 返回 False
func ScanYesOrNo(info string, defaultValue ...string) bool {
defV := "y"
if len(defaultValue) > 0 {
defV = defaultValue[0]
}
s := ScanWithDefault(defV, fmt.Sprintf("%s(y/n)", info))
for {
switch gstr.ToLower(gstr.TrimAll(s)) {
case "y":
return true
case "n":
return false
}
s = ScanAndLog("[ERROR] 输入错误请重新输入:")
}
}
// SelectOne 从选项中选择一个出来
// 默认选择 0
func SelectOne(options []string, msg string) (string, int) {
if len(options) == 1 {
return options[0], 0
}
if len(options) == 0 {
return "", -1
}
out := ""
for i, option := range options {
out += fmt.Sprintf("%d: %s \n", i+1, option)
}
if !g.IsEmpty(msg) {
out += fmt.Sprintf("* %s (默认:1) :", msg)
} else {
out += "* 请选择 (默认:1) :"
}
scan := gcmd.Scan(out)
for {
i := -1
switch scan {
case "":
i = 1
default:
i = gconv.Int(scan)
}
if i <= 0 || i > len(options) {
scan = gcmd.Scan("* 输入错误请重新输入:")
} else {
return options[i-1], i - 1
}
}
}
// ScanMdFiles 检索指定路径下的 md 文件。
func ScanMdFiles(path string) []string {
files, err := gfile.ScanDirFile(path, "*.md", true)
if err != nil {
yslog.Warning("检查出现错误了!", err)
return nil
}
return files
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。