etcdctl: cleanup etcdctl exit code

This commit is contained in:
Xiang Li
2015-06-02 19:01:41 -07:00
parent 711451ce2d
commit 26682b663d
5 changed files with 17 additions and 17 deletions

View File

@@ -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?

View File

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

View File

@@ -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 {

View File

@@ -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)
}

View File

@@ -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 {