2013-12-19 11:22:08 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-11-24 11:05:11 -08:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2015-03-30 14:50:45 -07:00
|
|
|
"syscall"
|
2014-11-24 11:05:11 -08:00
|
|
|
|
2013-12-19 11:22:08 -08:00
|
|
|
"github.com/hashicorp/consul/command"
|
2013-12-19 12:18:06 -08:00
|
|
|
"github.com/hashicorp/consul/command/agent"
|
2013-12-19 11:22:08 -08:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
2014-11-22 11:44:23 -06:00
|
|
|
// Commands is the mapping of all the available Consul commands.
|
2013-12-19 11:22:08 -08:00
|
|
|
var Commands map[string]cli.CommandFactory
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
ui := &cli.BasicUi{Writer: os.Stdout}
|
|
|
|
|
|
|
|
Commands = map[string]cli.CommandFactory{
|
2013-12-19 12:18:06 -08:00
|
|
|
"agent": func() (cli.Command, error) {
|
|
|
|
return &agent.Command{
|
2016-07-19 18:38:15 -07:00
|
|
|
Revision: GitCommit,
|
|
|
|
Version: Version,
|
|
|
|
VersionPrerelease: VersionPrerelease,
|
|
|
|
HumanVersion: GetHumanVersion(),
|
|
|
|
Ui: ui,
|
|
|
|
ShutdownCh: make(chan struct{}),
|
2013-12-19 12:18:06 -08:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2015-05-04 11:41:19 -07:00
|
|
|
"configtest": func() (cli.Command, error) {
|
|
|
|
return &command.ConfigTestCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-08-28 16:40:31 -07:00
|
|
|
"event": func() (cli.Command, error) {
|
|
|
|
return &command.EventCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-08-31 21:50:41 -07:00
|
|
|
"exec": func() (cli.Command, error) {
|
|
|
|
return &command.ExecCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-31 13:06:33 -08:00
|
|
|
"force-leave": func() (cli.Command, error) {
|
|
|
|
return &command.ForceLeaveCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-09-26 10:10:58 -05:00
|
|
|
"kv": func() (cli.Command, error) {
|
|
|
|
return &command.KVCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-09-26 10:12:40 -05:00
|
|
|
"kv delete": func() (cli.Command, error) {
|
|
|
|
return &command.KVDeleteCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-09-26 10:12:14 -05:00
|
|
|
"kv get": func() (cli.Command, error) {
|
|
|
|
return &command.KVGetCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-09-26 10:12:29 -05:00
|
|
|
"kv put": func() (cli.Command, error) {
|
|
|
|
return &command.KVPutCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-31 13:06:33 -08:00
|
|
|
"join": func() (cli.Command, error) {
|
|
|
|
return &command.JoinCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"keygen": func() (cli.Command, error) {
|
|
|
|
return &command.KeygenCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-09-12 20:08:54 -07:00
|
|
|
"keyring": func() (cli.Command, error) {
|
|
|
|
return &command.KeyringCommand{
|
2014-09-06 11:12:45 -07:00
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-31 13:06:33 -08:00
|
|
|
"leave": func() (cli.Command, error) {
|
|
|
|
return &command.LeaveCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2015-01-19 14:37:58 -10:00
|
|
|
"lock": func() (cli.Command, error) {
|
|
|
|
return &command.LockCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2015-01-21 13:00:14 -08:00
|
|
|
"maint": func() (cli.Command, error) {
|
|
|
|
return &command.MaintCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-31 13:06:33 -08:00
|
|
|
"members": func() (cli.Command, error) {
|
|
|
|
return &command.MembersCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"monitor": func() (cli.Command, error) {
|
|
|
|
return &command.MonitorCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-08-29 19:09:57 -07:00
|
|
|
"operator": func() (cli.Command, error) {
|
|
|
|
return &command.OperatorCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-02-23 16:59:32 -08:00
|
|
|
"info": func() (cli.Command, error) {
|
|
|
|
return &command.InfoCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-06-11 10:58:26 -07:00
|
|
|
"reload": func() (cli.Command, error) {
|
|
|
|
return &command.ReloadCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2015-10-16 00:03:16 -07:00
|
|
|
"rtt": func() (cli.Command, error) {
|
2015-10-21 17:21:08 -07:00
|
|
|
return &command.RTTCommand{
|
2015-10-16 00:03:16 -07:00
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-19 11:22:08 -08:00
|
|
|
"version": func() (cli.Command, error) {
|
|
|
|
return &command.VersionCommand{
|
2016-07-19 18:38:15 -07:00
|
|
|
HumanVersion: GetHumanVersion(),
|
|
|
|
Ui: ui,
|
2013-12-19 11:22:08 -08:00
|
|
|
}, nil
|
|
|
|
},
|
2014-08-21 16:02:41 -07:00
|
|
|
|
|
|
|
"watch": func() (cli.Command, error) {
|
|
|
|
return &command.WatchCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
2013-12-19 11:22:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeShutdownCh returns a channel that can be used for shutdown
|
|
|
|
// notifications for commands. This channel will send a message for every
|
2015-03-30 14:50:45 -07:00
|
|
|
// interrupt or SIGTERM received.
|
2013-12-19 11:22:08 -08:00
|
|
|
func makeShutdownCh() <-chan struct{} {
|
|
|
|
resultCh := make(chan struct{})
|
|
|
|
|
|
|
|
signalCh := make(chan os.Signal, 4)
|
2015-03-30 14:50:45 -07:00
|
|
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
|
2013-12-19 11:22:08 -08:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
<-signalCh
|
|
|
|
resultCh <- struct{}{}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return resultCh
|
|
|
|
}
|