代码拉取完成,页面将自动刷新
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())
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。