mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctl: cleanup etcdctl exit code
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -20,11 +20,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
SUCCESS = iota
|
||||
MalformedEtcdctlArguments
|
||||
FailedToConnectToHost
|
||||
FailedToAuth
|
||||
ErrorFromEtcd
|
||||
ExitSuccess = iota
|
||||
ExitBadArgs
|
||||
ExitBadConnection
|
||||
ExitBadAuth
|
||||
ExitServerError
|
||||
)
|
||||
|
||||
func handleError(code int, err error) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user