From 26682b663da84f02cbcd8f4b15534b863113e7ae Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Tue, 2 Jun 2015 19:01:41 -0700 Subject: [PATCH] etcdctl: cleanup etcdctl exit code --- etcdctl/command/cluster_health.go | 6 +++--- etcdctl/command/error.go | 10 +++++----- etcdctl/command/handle.go | 6 +++--- etcdctl/command/import_snap_command.go | 10 +++++----- etcdctl/command/watch_command.go | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/etcdctl/command/cluster_health.go b/etcdctl/command/cluster_health.go index fb94afb90..e62e801f5 100644 --- a/etcdctl/command/cluster_health.go +++ b/etcdctl/command/cluster_health.go @@ -27,11 +27,11 @@ func NewClusterHealthCommand() cli.Command { func handleClusterHealth(c *cli.Context) { endpoints, err := getEndpoints(c) if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } tr, err := getTransport(c) if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } client := etcd.NewClient(endpoints) @@ -42,7 +42,7 @@ func handleClusterHealth(c *cli.Context) { } 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? diff --git a/etcdctl/command/error.go b/etcdctl/command/error.go index 00e33f774..a43ff9b91 100644 --- a/etcdctl/command/error.go +++ b/etcdctl/command/error.go @@ -20,11 +20,11 @@ import ( ) const ( - SUCCESS = iota - MalformedEtcdctlArguments - FailedToConnectToHost - FailedToAuth - ErrorFromEtcd + ExitSuccess = iota + ExitBadArgs + ExitBadConnection + ExitBadAuth + ExitServerError ) func handleError(code int, err error) { diff --git a/etcdctl/command/handle.go b/etcdctl/command/handle.go index 4be649c2e..086dfbc71 100644 --- a/etcdctl/command/handle.go +++ b/etcdctl/command/handle.go @@ -60,7 +60,7 @@ func rawhandle(c *cli.Context, fn handlerFunc) (*etcd.Response, error) { // Sync cluster. if !c.GlobalBool("no-sync") { 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. if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } if resp != nil && pFn != nil { @@ -92,7 +92,7 @@ func handleContextualPrint(c *cli.Context, fn handlerFunc, pFn contextualPrintFu resp, err := rawhandle(c, fn) if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } if resp != nil && pFn != nil { diff --git a/etcdctl/command/import_snap_command.go b/etcdctl/command/import_snap_command.go index 859ad9d56..980e033c8 100644 --- a/etcdctl/command/import_snap_command.go +++ b/etcdctl/command/import_snap_command.go @@ -53,11 +53,11 @@ func handleImportSnap(c *cli.Context) { endpoints, err := getEndpoints(c) if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } tr, err := getTransport(c) if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } wg := &sync.WaitGroup{} @@ -73,7 +73,7 @@ func handleImportSnap(c *cli.Context) { } 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) go runSet(client, setc, wg) @@ -81,7 +81,7 @@ func handleImportSnap(c *cli.Context) { all, err := st.Get("/", true, true) if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } n := copyKeys(all.Node, setc) @@ -89,7 +89,7 @@ func handleImportSnap(c *cli.Context) { for _, h := range hiddens { allh, err := st.Get(h, true, true) if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } n += copyKeys(allh.Node, setc) } diff --git a/etcdctl/command/watch_command.go b/etcdctl/command/watch_command.go index fad4ba174..fa987c826 100644 --- a/etcdctl/command/watch_command.go +++ b/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) if err != nil { - handleError(ErrorFromEtcd, err) + handleError(ExitServerError, err) } if err != nil {