2013-12-19 19:22:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/command"
|
2013-12-19 20:18:06 +00:00
|
|
|
"github.com/hashicorp/consul/command/agent"
|
2013-12-19 19:22:08 +00:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Commands is the mapping of all the available Serf commands.
|
|
|
|
var Commands map[string]cli.CommandFactory
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
ui := &cli.BasicUi{Writer: os.Stdout}
|
|
|
|
|
|
|
|
Commands = map[string]cli.CommandFactory{
|
2013-12-19 20:18:06 +00:00
|
|
|
"agent": func() (cli.Command, error) {
|
|
|
|
return &agent.Command{
|
2014-06-06 21:40:22 +00:00
|
|
|
Revision: GitCommit,
|
|
|
|
Version: Version,
|
|
|
|
VersionPrerelease: VersionPrerelease,
|
|
|
|
Ui: ui,
|
|
|
|
ShutdownCh: make(chan struct{}),
|
2013-12-19 20:18:06 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-31 21:06:33 +00:00
|
|
|
"force-leave": func() (cli.Command, error) {
|
|
|
|
return &command.ForceLeaveCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"join": func() (cli.Command, error) {
|
|
|
|
return &command.JoinCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"keygen": func() (cli.Command, error) {
|
|
|
|
return &command.KeygenCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"leave": func() (cli.Command, error) {
|
|
|
|
return &command.LeaveCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"members": func() (cli.Command, error) {
|
|
|
|
return &command.MembersCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"monitor": func() (cli.Command, error) {
|
|
|
|
return &command.MonitorCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-02-24 00:59:32 +00:00
|
|
|
"info": func() (cli.Command, error) {
|
|
|
|
return &command.InfoCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-06-11 17:58:26 +00:00
|
|
|
"reload": func() (cli.Command, error) {
|
|
|
|
return &command.ReloadCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-19 19:22:08 +00:00
|
|
|
"version": func() (cli.Command, error) {
|
|
|
|
return &command.VersionCommand{
|
|
|
|
Revision: GitCommit,
|
|
|
|
Version: Version,
|
|
|
|
VersionPrerelease: VersionPrerelease,
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
2014-08-21 23:02:41 +00:00
|
|
|
|
|
|
|
"watch": func() (cli.Command, error) {
|
|
|
|
return &command.WatchCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
2013-12-19 19:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeShutdownCh returns a channel that can be used for shutdown
|
|
|
|
// notifications for commands. This channel will send a message for every
|
|
|
|
// interrupt received.
|
|
|
|
func makeShutdownCh() <-chan struct{} {
|
|
|
|
resultCh := make(chan struct{})
|
|
|
|
|
|
|
|
signalCh := make(chan os.Signal, 4)
|
|
|
|
signal.Notify(signalCh, os.Interrupt)
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
<-signalCh
|
|
|
|
resultCh <- struct{}{}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return resultCh
|
|
|
|
}
|