Ver Fonte

etcdctl: cleanup etcdctl exit code

Xiang Li há 10 anos atrás
pai
commit
26682b663d

+ 3 - 3
etcdctl/command/cluster_health.go

@@ -27,11 +27,11 @@ func NewClusterHealthCommand() cli.Command {
 func handleClusterHealth(c *cli.Context) {
 func handleClusterHealth(c *cli.Context) {
 	endpoints, err := getEndpoints(c)
 	endpoints, err := getEndpoints(c)
 	if err != nil {
 	if err != nil {
-		handleError(ErrorFromEtcd, err)
+		handleError(ExitServerError, err)
 	}
 	}
 	tr, err := getTransport(c)
 	tr, err := getTransport(c)
 	if err != nil {
 	if err != nil {
-		handleError(ErrorFromEtcd, err)
+		handleError(ExitServerError, err)
 	}
 	}
 
 
 	client := etcd.NewClient(endpoints)
 	client := etcd.NewClient(endpoints)
@@ -42,7 +42,7 @@ func handleClusterHealth(c *cli.Context) {
 	}
 	}
 
 
 	if ok := client.SyncCluster(); !ok {
 	if ok := client.SyncCluster(); !ok {
-		handleError(FailedToConnectToHost, errors.New("cannot sync with the cluster using endpoints "+strings.Join(endpoints, ", ")))
+		handleError(ExitBadConnection, errors.New("cannot sync with the cluster using endpoints "+strings.Join(endpoints, ", ")))
 	}
 	}
 
 
 	// do we have a leader?
 	// do we have a leader?

+ 5 - 5
etcdctl/command/error.go

@@ -20,11 +20,11 @@ import (
 )
 )
 
 
 const (
 const (
-	SUCCESS = iota
-	MalformedEtcdctlArguments
-	FailedToConnectToHost
-	FailedToAuth
-	ErrorFromEtcd
+	ExitSuccess = iota
+	ExitBadArgs
+	ExitBadConnection
+	ExitBadAuth
+	ExitServerError
 )
 )
 
 
 func handleError(code int, err error) {
 func handleError(code int, err error) {

+ 3 - 3
etcdctl/command/handle.go

@@ -60,7 +60,7 @@ func rawhandle(c *cli.Context, fn handlerFunc) (*etcd.Response, error) {
 	// Sync cluster.
 	// Sync cluster.
 	if !c.GlobalBool("no-sync") {
 	if !c.GlobalBool("no-sync") {
 		if ok := client.SyncCluster(); !ok {
 		if ok := client.SyncCluster(); !ok {
-			handleError(FailedToConnectToHost, errors.New("cannot sync with the cluster using endpoints "+strings.Join(endpoints, ", ")))
+			handleError(ExitBadConnection, errors.New("cannot sync with the cluster using endpoints "+strings.Join(endpoints, ", ")))
 		}
 		}
 	}
 	}
 
 
@@ -79,7 +79,7 @@ func handlePrint(c *cli.Context, fn handlerFunc, pFn printFunc) {
 
 
 	// Print error and exit, if necessary.
 	// Print error and exit, if necessary.
 	if err != nil {
 	if err != nil {
-		handleError(ErrorFromEtcd, err)
+		handleError(ExitServerError, err)
 	}
 	}
 
 
 	if resp != nil && pFn != nil {
 	if resp != nil && pFn != nil {
@@ -92,7 +92,7 @@ func handleContextualPrint(c *cli.Context, fn handlerFunc, pFn contextualPrintFu
 	resp, err := rawhandle(c, fn)
 	resp, err := rawhandle(c, fn)
 
 
 	if err != nil {
 	if err != nil {
-		handleError(ErrorFromEtcd, err)
+		handleError(ExitServerError, err)
 	}
 	}
 
 
 	if resp != nil && pFn != nil {
 	if resp != nil && pFn != nil {

+ 5 - 5
etcdctl/command/import_snap_command.go

@@ -53,11 +53,11 @@ func handleImportSnap(c *cli.Context) {
 
 
 	endpoints, err := getEndpoints(c)
 	endpoints, err := getEndpoints(c)
 	if err != nil {
 	if err != nil {
-		handleError(ErrorFromEtcd, err)
+		handleError(ExitServerError, err)
 	}
 	}
 	tr, err := getTransport(c)
 	tr, err := getTransport(c)
 	if err != nil {
 	if err != nil {
-		handleError(ErrorFromEtcd, err)
+		handleError(ExitServerError, err)
 	}
 	}
 
 
 	wg := &sync.WaitGroup{}
 	wg := &sync.WaitGroup{}
@@ -73,7 +73,7 @@ func handleImportSnap(c *cli.Context) {
 		}
 		}
 
 
 		if ok := client.SyncCluster(); !ok {
 		if ok := client.SyncCluster(); !ok {
-			handleError(FailedToConnectToHost, errors.New("cannot sync with the cluster using endpoints "+strings.Join(endpoints, ", ")))
+			handleError(ExitBadConnection, errors.New("cannot sync with the cluster using endpoints "+strings.Join(endpoints, ", ")))
 		}
 		}
 		wg.Add(1)
 		wg.Add(1)
 		go runSet(client, setc, wg)
 		go runSet(client, setc, wg)
@@ -81,7 +81,7 @@ func handleImportSnap(c *cli.Context) {
 
 
 	all, err := st.Get("/", true, true)
 	all, err := st.Get("/", true, true)
 	if err != nil {
 	if err != nil {
-		handleError(ErrorFromEtcd, err)
+		handleError(ExitServerError, err)
 	}
 	}
 	n := copyKeys(all.Node, setc)
 	n := copyKeys(all.Node, setc)
 
 
@@ -89,7 +89,7 @@ func handleImportSnap(c *cli.Context) {
 	for _, h := range hiddens {
 	for _, h := range hiddens {
 		allh, err := st.Get(h, true, true)
 		allh, err := st.Get(h, true, true)
 		if err != nil {
 		if err != nil {
-			handleError(ErrorFromEtcd, err)
+			handleError(ExitServerError, err)
 		}
 		}
 		n += copyKeys(allh.Node, setc)
 		n += copyKeys(allh.Node, setc)
 	}
 	}

+ 1 - 1
etcdctl/command/watch_command.go

@@ -86,7 +86,7 @@ func watchCommandFunc(c *cli.Context, client *etcd.Client) (*etcd.Response, erro
 		resp, err = client.Watch(key, uint64(index), recursive, nil, nil)
 		resp, err = client.Watch(key, uint64(index), recursive, nil, nil)
 
 
 		if err != nil {
 		if err != nil {
-			handleError(ErrorFromEtcd, err)
+			handleError(ExitServerError, err)
 		}
 		}
 
 
 		if err != nil {
 		if err != nil {