Ai
1 Star 0 Fork 0

妙音/kits

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
miaoyin 提交于 2022-04-02 11:25 +08:00 . feat: kit-shell 执行shell命令
package main
import (
"flag"
"fmt"
"os"
"gitee.com/xuender/kits/cmd"
"gitee.com/xuender/kits/pb"
"gitee.com/xuender/oils/base"
"gitee.com/xuender/oils/execs"
"gitee.com/xuender/oils/logs"
)
func main() {
flag.CommandLine.Usage = usage
config := pb.NewConfig("./shell.toml")
config.Parse()
if config.Command == "" {
logs.Panic("缺少执行命令")
}
if len(config.Env) > 0 {
for key, value := range config.Env {
config.Env[key] = os.Getenv(value)
}
for index, key := range config.Args {
if value, has := config.Env[key]; has {
config.Args[index] = value
}
}
}
logs.Info(config)
out, err := execs.ExecOut(config.Command, config.Args...)
logs.Error(out)
base.Panic(err)
}
func usage() {
fmt.Fprintf(flag.CommandLine.Output(), "kit-shell[%s]\n\n", cmd.ModVersion)
fmt.Fprintf(flag.CommandLine.Output(), "根据配置执行命令\n\n")
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprintf(flag.CommandLine.Output(), "\n模块: %s\n提交: %s\n", cmd.ModPath, cmd.ModSum)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xuender/kits.git
git@gitee.com:xuender/kits.git
xuender
kits
kits
v1.0.10

搜索帮助