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/lib"
|
||||||
"github.com/hashicorp/consul/logging"
|
"github.com/hashicorp/consul/logging"
|
||||||
"github.com/hashicorp/consul/service_os"
|
"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{
|
ui = &cli.PrefixedUi{
|
||||||
OutputPrefix: "==> ",
|
OutputPrefix: "==> ",
|
||||||
InfoPrefix: " ",
|
InfoPrefix: " ",
|
||||||
|
@ -33,11 +34,10 @@ func New(ui cli.Ui, revision, version, versionPre, versionHuman string, shutdown
|
||||||
|
|
||||||
c := &cmd{
|
c := &cmd{
|
||||||
UI: ui,
|
UI: ui,
|
||||||
revision: revision,
|
revision: consulversion.GitCommit,
|
||||||
version: version,
|
version: consulversion.Version,
|
||||||
versionPrerelease: versionPre,
|
versionPrerelease: consulversion.VersionPrerelease,
|
||||||
versionHuman: versionHuman,
|
versionHuman: consulversion.GetHumanVersion(),
|
||||||
shutdownCh: shutdownCh,
|
|
||||||
flags: flag.NewFlagSet("", flag.ContinueOnError),
|
flags: flag.NewFlagSet("", flag.ContinueOnError),
|
||||||
}
|
}
|
||||||
config.AddFlags(c.flags, &c.configLoadOpts)
|
config.AddFlags(c.flags, &c.configLoadOpts)
|
||||||
|
@ -58,7 +58,6 @@ type cmd struct {
|
||||||
version string
|
version string
|
||||||
versionPrerelease string
|
versionPrerelease string
|
||||||
versionHuman string
|
versionHuman string
|
||||||
shutdownCh <-chan struct{}
|
|
||||||
configLoadOpts config.LoadOpts
|
configLoadOpts config.LoadOpts
|
||||||
logger hclog.InterceptLogger
|
logger hclog.InterceptLogger
|
||||||
}
|
}
|
||||||
|
@ -281,8 +280,6 @@ func (c *cmd) run(args []string) int {
|
||||||
sig = s
|
sig = s
|
||||||
case <-service_os.Shutdown_Channel():
|
case <-service_os.Shutdown_Channel():
|
||||||
sig = os.Interrupt
|
sig = os.Interrupt
|
||||||
case <-c.shutdownCh:
|
|
||||||
sig = os.Interrupt
|
|
||||||
case err := <-agent.RetryJoinCh():
|
case err := <-agent.RetryJoinCh():
|
||||||
c.logger.Error("Retry join failed", "error", err)
|
c.logger.Error("Retry join failed", "error", err)
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -8,12 +8,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/testrpc"
|
"github.com/mitchellh/cli"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent"
|
"github.com/hashicorp/consul/agent"
|
||||||
"github.com/hashicorp/consul/sdk/testutil"
|
"github.com/hashicorp/consul/sdk/testutil"
|
||||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
"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.
|
// 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")
|
tmpDir := testutil.TempDir(t, "consul")
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := New(ui, "", "", "", "", nil)
|
cmd := New(ui)
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-bind", "127.0.0.1",
|
"-bind", "127.0.0.1",
|
||||||
|
@ -145,7 +145,7 @@ func TestRetryJoinWanFail(t *testing.T) {
|
||||||
tmpDir := testutil.TempDir(t, "consul")
|
tmpDir := testutil.TempDir(t, "consul")
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := New(ui, "", "", "", "", nil)
|
cmd := New(ui)
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-server",
|
"-server",
|
||||||
|
@ -184,7 +184,7 @@ func TestProtectDataDir(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := New(ui, "", "", "", "", nil)
|
cmd := New(ui)
|
||||||
args := []string{"-config-file=" + cfgFile.Name()}
|
args := []string{"-config-file=" + cfgFile.Name()}
|
||||||
if code := cmd.Run(args); code == 0 {
|
if code := cmd.Run(args); code == 0 {
|
||||||
t.Fatalf("should fail")
|
t.Fatalf("should fail")
|
||||||
|
@ -203,7 +203,7 @@ func TestBadDataDirPermissions(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ui := cli.NewMockUi()
|
ui := cli.NewMockUi()
|
||||||
cmd := New(ui, "", "", "", "", nil)
|
cmd := New(ui)
|
||||||
args := []string{"-data-dir=" + dataDir, "-server=true", "-bind=10.0.0.1"}
|
args := []string{"-data-dir=" + dataDir, "-server=true", "-bind=10.0.0.1"}
|
||||||
if code := cmd.Run(args); code == 0 {
|
if code := cmd.Run(args); code == 0 {
|
||||||
t.Fatalf("Should fail with bad data directory permissions")
|
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/validate"
|
||||||
"github.com/hashicorp/consul/command/version"
|
"github.com/hashicorp/consul/command/version"
|
||||||
"github.com/hashicorp/consul/command/watch"
|
"github.com/hashicorp/consul/command/watch"
|
||||||
consulversion "github.com/hashicorp/consul/version"
|
|
||||||
|
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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", 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 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 })
|
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 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 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("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) {
|
Register("agent", func(ui cli.Ui) (cli.Command, error) { return agent.New(ui), nil })
|
||||||
return agent.New(ui, rev, ver, verPre, verHuman, make(chan struct{})), nil
|
|
||||||
})
|
|
||||||
Register("catalog", func(cli.Ui) (cli.Command, error) { return catalog.New(), 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 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 })
|
Register("catalog nodes", func(ui cli.Ui) (cli.Command, error) { return catlistnodes.New(ui), nil })
|
||||||
|
|
Loading…
Reference in New Issue