1 Star 3 Fork 0

墨城/wait_cli

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
root.go 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
qdmc 提交于 2021-09-02 14:04 +08:00 . project
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"os"
"github.com/spf13/viper"
)
var cfgFile string
// 根命令
var RootCmd = &cobra.Command{
Use: "wait_command",
Short: "命令行阻塞工具",
Long: `命令阻塞进程不退出,等待Stdin输出,cobra解析命令行`,
}
// 执行命令行
func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
//os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.golang_chan.yaml)")
RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := os.UserHomeDir()
cobra.CheckErr(err)
// Search config in home directory with name ".golang_chan" (without extension).
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
viper.SetConfigName(".golang_chan")
}
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/qdmc/wait_cli.git
git@gitee.com:qdmc/wait_cli.git
qdmc
wait_cli
wait_cli
v1.1.1

搜索帮助