mirror of https://github.com/status-im/consul.git
cmd: remove unnecessary args to agent.New
The version args are static and passed in from the caller. Instead read the static values in New. The shutdownCh was never closed, so did nothing. Remove it as a field and an arg.
This commit is contained in:
parent
071007e3fd
commit
e573641995
|
@ -21,9 +21,10 @@ import (
|
|||
"github.com/hashicorp/consul/lib"
|
||||
"github.com/hashicorp/consul/logging"
|
||||
"github.com/hashicorp/consul/service_os"
|
||||
consulversion "github.com/hashicorp/consul/version"
|
||||
)
|
||||
|
||||
func New(ui cli.Ui, revision, version, versionPre, versionHuman string, shutdownCh <-chan struct{}) *cmd {
|
||||
func New(ui cli.Ui) *cmd {
|
||||
ui = &cli.PrefixedUi{
|
||||
OutputPrefix: "==> ",
|
||||
InfoPrefix: " ",
|
||||
|
@ -33,11 +34,10 @@ func New(ui cli.Ui, revision, version, versionPre, versionHuman string, shutdown
|
|||
|
||||
c := &cmd{
|
||||
UI: ui,
|
||||
revision: revision,
|
||||
version: version,
|
||||
versionPrerelease: versionPre,
|
||||
versionHuman: versionHuman,
|
||||
shutdownCh: shutdownCh,
|
||||
revision: consulversion.GitCommit,
|
||||
version: consulversion.Version,
|
||||
versionPrerelease: consulversion.VersionPrerelease,
|
||||
versionHuman: consulversion.GetHumanVersion(),
|
||||
flags: flag.NewFlagSet("", flag.ContinueOnError),
|
||||
}
|
||||
config.AddFlags(c.flags, &c.configLoadOpts)
|
||||
|
@ -58,7 +58,6 @@ type cmd struct {
|
|||
version string
|
||||
versionPrerelease string
|
||||
versionHuman string
|
||||
shutdownCh <-chan struct{}
|
||||
configLoadOpts config.LoadOpts
|
||||
logger hclog.InterceptLogger
|
||||
}
|
||||
|
@ -281,8 +280,6 @@ func (c *cmd) run(args []string) int {
|
|||
sig = s
|
||||
case <-service_os.Shutdown_Channel():
|
||||
sig = os.Interrupt
|
||||
case <-c.shutdownCh:
|
||||
sig = os.Interrupt
|
||||
case err := <-agent.RetryJoinCh():
|
||||
c.logger.Error("Retry join failed", "error", err)
|
||||
return 1
|
||||
|
|
|
@ -8,12 +8,12 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/consul/testrpc"
|
||||
"github.com/mitchellh/cli"
|
||||
|
||||
"github.com/hashicorp/consul/agent"
|
||||
"github.com/hashicorp/consul/sdk/testutil"
|
||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/hashicorp/consul/testrpc"
|
||||
)
|
||||
|
||||
// TestConfigFail should test command line flags that lead to an immediate error.
|
||||
|
@ -121,7 +121,7 @@ func TestRetryJoinFail(t *testing.T) {
|
|||
tmpDir := testutil.TempDir(t, "consul")
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
cmd := New(ui, "", "", "", "", nil)
|
||||
cmd := New(ui)
|
||||
|
||||
args := []string{
|
||||
"-bind", "127.0.0.1",
|
||||
|
@ -145,7 +145,7 @@ func TestRetryJoinWanFail(t *testing.T) {
|
|||
tmpDir := testutil.TempDir(t, "consul")
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
cmd := New(ui, "", "", "", "", nil)
|
||||
cmd := New(ui)
|
||||
|
||||
args := []string{
|
||||
"-server",
|
||||
|
@ -184,7 +184,7 @@ func TestProtectDataDir(t *testing.T) {
|
|||
}
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
cmd := New(ui, "", "", "", "", nil)
|
||||
cmd := New(ui)
|
||||
args := []string{"-config-file=" + cfgFile.Name()}
|
||||
if code := cmd.Run(args); code == 0 {
|
||||
t.Fatalf("should fail")
|
||||
|
@ -203,7 +203,7 @@ func TestBadDataDirPermissions(t *testing.T) {
|
|||
}
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
cmd := New(ui, "", "", "", "", nil)
|
||||
cmd := New(ui)
|
||||
args := []string{"-data-dir=" + dataDir, "-server=true", "-bind=10.0.0.1"}
|
||||
if code := cmd.Run(args); code == 0 {
|
||||
t.Fatalf("Should fail with bad data directory permissions")
|
||||
|
|
|
@ -108,17 +108,11 @@ import (
|
|||
"github.com/hashicorp/consul/command/validate"
|
||||
"github.com/hashicorp/consul/command/version"
|
||||
"github.com/hashicorp/consul/command/watch"
|
||||
consulversion "github.com/hashicorp/consul/version"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rev := consulversion.GitCommit
|
||||
ver := consulversion.Version
|
||||
verPre := consulversion.VersionPrerelease
|
||||
verHuman := consulversion.GetHumanVersion()
|
||||
|
||||
Register("acl", func(cli.Ui) (cli.Command, error) { return acl.New(), nil })
|
||||
Register("acl bootstrap", func(ui cli.Ui) (cli.Command, error) { return aclbootstrap.New(ui), nil })
|
||||
Register("acl policy", func(cli.Ui) (cli.Command, error) { return aclpolicy.New(), nil })
|
||||
|
@ -154,9 +148,7 @@ func init() {
|
|||
Register("acl binding-rule read", func(ui cli.Ui) (cli.Command, error) { return aclbrread.New(ui), nil })
|
||||
Register("acl binding-rule update", func(ui cli.Ui) (cli.Command, error) { return aclbrupdate.New(ui), nil })
|
||||
Register("acl binding-rule delete", func(ui cli.Ui) (cli.Command, error) { return aclbrdelete.New(ui), nil })
|
||||
Register("agent", func(ui cli.Ui) (cli.Command, error) {
|
||||
return agent.New(ui, rev, ver, verPre, verHuman, make(chan struct{})), nil
|
||||
})
|
||||
Register("agent", func(ui cli.Ui) (cli.Command, error) { return agent.New(ui), nil })
|
||||
Register("catalog", func(cli.Ui) (cli.Command, error) { return catalog.New(), nil })
|
||||
Register("catalog datacenters", func(ui cli.Ui) (cli.Command, error) { return catlistdc.New(ui), nil })
|
||||
Register("catalog nodes", func(ui cli.Ui) (cli.Command, error) { return catlistnodes.New(ui), nil })
|
||||
|
|
Loading…
Reference in New Issue