[agent-wdd] 完成自定义log部分;完成info network部分; 项目结构基本完成
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"agent-wdd/config"
|
||||
"agent-wdd/log"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
)
|
||||
|
||||
const WddConfigFilePath = "/usr/local/etc/wdd/"
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "wdd",
|
||||
Short: "wdd应用程序是wdd封装的NB工具",
|
||||
@@ -23,7 +22,7 @@ var projectBase = ""
|
||||
|
||||
func init() {
|
||||
|
||||
cobra.OnInitialize(initConfig)
|
||||
cobra.OnInitialize(config.InitConfig)
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
|
||||
rootCmd.PersistentFlags().StringVarP(&projectBase, "projectbase", "b", "",
|
||||
@@ -38,24 +37,6 @@ func init() {
|
||||
viper.SetDefault("license", "apache")
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
// Don't forget to read config either from cfgFile or from home directory!
|
||||
if cfgFile != "" {
|
||||
// Use config file from the flag.
|
||||
viper.SetConfigFile(cfgFile)
|
||||
} else {
|
||||
|
||||
// Search config in home directory with name ".cobra" (without extension).
|
||||
viper.AddConfigPath(WddConfigFilePath)
|
||||
viper.SetConfigName(".cobra")
|
||||
}
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
fmt.Println("Can't read config:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
|
||||
// 1. base命令
|
||||
@@ -103,10 +84,8 @@ func Execute() {
|
||||
infoCmd := &cobra.Command{
|
||||
Use: "info",
|
||||
Short: "打印主机详细信息",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// 实现info逻辑
|
||||
},
|
||||
}
|
||||
addInfoSubcommands(infoCmd)
|
||||
|
||||
// 8. version命令
|
||||
versionCmd := &cobra.Command{
|
||||
@@ -114,6 +93,10 @@ func Execute() {
|
||||
Short: "打印版本信息",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// 实现version逻辑
|
||||
log.Debug("来自王达达的礼物 !")
|
||||
log.Info("来自王达达的礼物 !")
|
||||
log.Warning("来自王达达的礼物 !")
|
||||
log.Error("来自王达达的礼物 !")
|
||||
},
|
||||
}
|
||||
|
||||
@@ -149,8 +132,4 @@ func Execute() {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user