mirror of
https://github.com/status-im/consul.git
synced 2025-01-24 04:31:12 +00:00
a49711b8bf
This patch refactors the commands that use the mitchellh/cli library to populate the command line flag set in both the Run() and the Help() method. Earlier versions of the mitchellh/cli library relied on the Run() method to populuate the flagset for generating the usage screen. This has changed in later versions and was previously solved with a small monkey patch to the library to restore the old behavior. However, this makes upgrading the library difficult since the patch has to be restored every time. This patch addresses this by moving the command line flags into an initFlags() method where appropriate and also moving all variables for the flags from the Run() method into the command itself. Fixes #3536
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// ForceLeaveCommand is a Command implementation that tells a running Consul
|
|
// to force a member to enter the "left" state.
|
|
type ForceLeaveCommand struct {
|
|
BaseCommand
|
|
}
|
|
|
|
func (c *ForceLeaveCommand) Run(args []string) int {
|
|
c.InitFlagSet()
|
|
if err := c.FlagSet.Parse(args); err != nil {
|
|
return 1
|
|
}
|
|
|
|
nodes := c.FlagSet.Args()
|
|
if len(nodes) != 1 {
|
|
c.UI.Error("A single node name must be specified to force leave.")
|
|
c.UI.Error("")
|
|
c.UI.Error(c.Help())
|
|
return 1
|
|
}
|
|
|
|
client, err := c.HTTPClient()
|
|
if err != nil {
|
|
c.UI.Error(fmt.Sprintf("Error connecting to Consul agent: %s", err))
|
|
return 1
|
|
}
|
|
|
|
err = client.Agent().ForceLeave(nodes[0])
|
|
if err != nil {
|
|
c.UI.Error(fmt.Sprintf("Error force leaving: %s", err))
|
|
return 1
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
func (c *ForceLeaveCommand) Help() string {
|
|
c.InitFlagSet()
|
|
return c.HelpCommand(`
|
|
Usage: consul force-leave [options] name
|
|
|
|
Forces a member of a Consul cluster to enter the "left" state. Note
|
|
that if the member is still actually alive, it will eventually rejoin
|
|
the cluster. This command is most useful for cleaning out "failed" nodes
|
|
that are never coming back. If you do not force leave a failed node,
|
|
Consul will attempt to reconnect to those failed nodes for some period of
|
|
time before eventually reaping them.
|
|
|
|
`)
|
|
}
|
|
|
|
func (c *ForceLeaveCommand) Synopsis() string {
|
|
return "Forces a member of the cluster to enter the \"left\" state"
|
|
}
|