Skip to content

Commit

Permalink
Merge pull request labring#363 from cuisongliu/feature/validate
Browse files Browse the repository at this point in the history
feat(develop): 验证参数数据
  • Loading branch information
cuisongliu authored May 28, 2020
2 parents 3901880 + ba211df commit 65c5de4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"fmt"
"github.com/fanux/sealos/install"
"github.com/spf13/cobra"
"github.com/wonderivan/logger"
"os"
)

var contact = `
Expand Down Expand Up @@ -50,6 +52,18 @@ var initCmd = &cobra.Command{
c.Dump("")
fmt.Println(contact)
},
PreRun: func(cmd *cobra.Command, args []string) {
if len(install.MasterIPs) == 0 {
logger.Error("this command is init feature,master can't is empty.please check your command is ok?")
cmd.Help()
os.Exit(0)
}
if AppURL == "" {
logger.Error("your pkg-url is empty,please check your command is ok?")
cmd.Help()
os.Exit(0)
}
},
}

func init() {
Expand Down
9 changes: 9 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package cmd
import (
"github.com/fanux/sealos/install"
"github.com/spf13/cobra"
"github.com/wonderivan/logger"
"os"
)

var AppURL string
Expand All @@ -29,6 +31,13 @@ var installCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
install.AppInstall(AppURL)
},
PreRun: func(cmd *cobra.Command, args []string) {
if AppURL == "" {
logger.Error("your pkg-url is empty,please check your command is ok?")
cmd.Help()
os.Exit(0)
}
},
}
var name string

Expand Down
7 changes: 7 additions & 0 deletions cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ var joinCmd = &cobra.Command{
Use: "join",
Short: "Simplest way to join your kubernets HA cluster",
Long: `sealos join --node 192.168.0.5`,
PreRun: func(cmd *cobra.Command, args []string) {
if len(install.MasterIPs) == 0 && len(install.NodeIPs) == 0 {
logger.Error("this command is join feature,master and node is empty at the same time.please check your args in command.")
cmd.Help()
os.Exit(0)
}
},
Run: func(cmd *cobra.Command, args []string) {
beforeNodes := install.ParseIPs(install.NodeIPs)
beforeMasters := install.ParseIPs(install.MasterIPs)
Expand Down
2 changes: 1 addition & 1 deletion install/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ all:
}
end:
if len(i.Masters) == 0 && len(i.Nodes) == 0 {
logger.Debug("clean nodes and masters is skip")
logger.Warn("clean nodes and masters is empty,please check your args and config.yaml.")
os.Exit(-1)
}
i.CheckValid()
Expand Down

0 comments on commit 65c5de4

Please sign in to comment.