Merge pull request #5212 from sebito91/master

adding quit and ctrl-d support to influx cli
pull/5215/head
Philip O'Toole 2015-12-23 14:24:13 -05:00
commit 3489c30b85
2 changed files with 28 additions and 4 deletions

View File

@ -68,7 +68,7 @@ func New(version string) *CommandLine {
// Run executes the CLI
func (c *CommandLine) Run() {
// register OS signals for graceful termination
signal.Notify(c.osSignals, os.Kill, os.Interrupt, syscall.SIGTERM)
signal.Notify(c.osSignals, os.Kill, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP)
var promptForPassword bool
// determine if they set the password flag but provided no value
@ -180,7 +180,10 @@ func (c *CommandLine) Run() {
c.exit()
default:
l, e := c.Line.Prompt("> ")
if e != nil {
if e == io.EOF {
// Instead of die, register that someone exited the program gracefully
l = "exit"
} else if e != nil {
break
}
if c.ParseCommand(l) {
@ -201,7 +204,7 @@ func (c *CommandLine) ParseCommand(cmd string) bool {
if len(tokens) > 0 {
switch tokens[0] {
case "exit":
case "exit", "quit":
// signal the program to exit
close(c.Quit)
case "gopher":
@ -731,7 +734,7 @@ func (c *CommandLine) help() {
consistency <level> sets write consistency level: any, one, quorum, or all
history displays command history
settings outputs the current settings for the shell
exit quits the influx shell
exit/quit/ctrl+d quits the influx shell
show databases show database names
show series show series information

View File

@ -237,6 +237,27 @@ func TestParseCommand_Exit(t *testing.T) {
}
}
func TestParseCommand_Quit(t *testing.T) {
t.Parallel()
tests := []struct {
cmd string
}{
{cmd: "quit"},
{cmd: " quit"},
{cmd: "quit "},
{cmd: "Quit "},
}
for _, test := range tests {
c := cli.CommandLine{Quit: make(chan struct{}, 1)}
c.ParseCommand(test.cmd)
// channel should be closed
if _, ok := <-c.Quit; ok {
t.Fatalf(`Command "quit" failed for %q.`, test.cmd)
}
}
}
func TestParseCommand_Use(t *testing.T) {
t.Parallel()
c := cli.CommandLine{}