diff --git a/cmd/generate.go b/cmd/generate.go index 9092fd6..92092c3 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -64,6 +64,10 @@ func init() { } func BootstrapChainConf() { + if _, err := os.Stat(conf.UserHome + "/.telescope/conf.d/" + ChainName + ".toml"); !os.IsNotExist(err) { + fmt.Printf("config file for chain %s exits", ChainName) + os.Exit(1) + } for { fmt.Fprint(os.Stderr, "Add new chain "+ChainName+" ?(Y/n): ") s, _ = r.ReadString('\n') diff --git a/cmd/verify.go b/cmd/verify.go index ba6c487..91a9583 100644 --- a/cmd/verify.go +++ b/cmd/verify.go @@ -7,6 +7,8 @@ package cmd import ( "fmt" + "github.com/gadost/telescope/conf" + "github.com/gadost/telescope/watcher" "github.com/spf13/cobra" ) @@ -16,11 +18,34 @@ var verifyCmd = &cobra.Command{ Short: "verify configs", Long: ``, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("verify called") + Verify() }, } func init() { configCmd.AddCommand(verifyCmd) - verifyCmd.Flags().StringVarP(&ChainName, "chain", "c", "", "Chain name") + verifyCmd.PersistentFlags().StringVarP(&c, "conf", "c", conf.UserHome+"/.telescope/conf.d", "Configurations directory") +} + +func Verify() { + cfg, chains := conf.ConfLoad(c) + for _, chainName := range chains { + if cfg.Chain[chainName].Info.Github != "" { + + repoInfo := watcher.Parse(cfg.Chain[chainName].Info.Github) + if repoInfo.Domain == "" || repoInfo.Owner == "" && repoInfo.RepoName == "" { + fmt.Printf("Can't parse %s as github repository", cfg.Chain[chainName].Info.Github) + } + } + + for _, node := range cfg.Chain[chainName].Node { + if node.Role != "validator" && node.Role != "sentry" { + fmt.Printf("Can't parse node type %s , chain: %s", node.Role, chainName) + } + if node.RPC == "" { + fmt.Printf("empty RPC for node , chain: %s", chainName) + } + } + } + }