1 Star 0 Fork 1

yss930819/gf-ex

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
other.go 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
yss930819 提交于 2023-02-10 10:37 +08:00 . feat: 增加配置文件的默认路径设置
package yscmd
import (
"context"
"fmt"
"gitee.com/kmyss/gf-ex/ysansi"
"gitee.com/kmyss/gf-ex/yslog"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/util/gconv"
"time"
)
// TimeToClose 延迟xx秒并显示提示
func TimeToClose(t int) {
TimeToCloseShell(context.TODO(), t)
}
// TimeToCloseShell 在 shell 模式下的退出方式
// 在 shell 模式下不执行等待
func TimeToCloseShell(ctx context.Context, t int) {
if IsShell(ctx) {
return
}
yslog.Printf("~~%d 秒后自动关闭~~", t)
for i := 0; i < t; i++ {
yslog.Printf("%3d s.....", t-i)
time.Sleep(1 * time.Second)
ysansi.DoClearOneLine()
}
}
// SelectFile 遍历文件夹下的文件内容让用户选择
// 不查找子文件夹
func SelectFile(path string, pattern string) string {
files, err := gfile.ScanDirFile(gfile.Abs(path), pattern)
if err != nil || !(len(files) > 0) {
yslog.Error("未查询到需要的文件!")
return ""
}
out := ""
for i, name := range files {
out += fmt.Sprintf("%d: %s \n", i+1, gfile.Basename(name))
}
out += "* 请选择文件 (默认:1) :"
scan := gcmd.Scan(out)
for {
i := -1
switch scan {
case "":
i = 1
default:
i = gconv.Int(scan)
}
if i <= 0 || i > len(files) {
scan = gcmd.Scan("* 输入错误请重新输入:")
} else {
return files[i-1]
}
}
}
// SelectConfig 找寻当前目录下的配置文件
func SelectConfig() string {
return SelectFile("./config", "*.toml")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kmyss/gf-ex.git
git@gitee.com:kmyss/gf-ex.git
kmyss
gf-ex
gf-ex
v1.0.5

搜索帮助