aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/shell_liner.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/shell/shell_liner.go')
-rw-r--r--weed/shell/shell_liner.go81
1 files changed, 45 insertions, 36 deletions
diff --git a/weed/shell/shell_liner.go b/weed/shell/shell_liner.go
index a4f17e0fa..1dd611ca5 100644
--- a/weed/shell/shell_liner.go
+++ b/weed/shell/shell_liner.go
@@ -2,13 +2,13 @@ package shell
import (
"fmt"
+ "github.com/chrislusf/seaweedfs/weed/util/grace"
"io"
"os"
"path"
"regexp"
- "strings"
-
"sort"
+ "strings"
"github.com/peterh/liner"
)
@@ -20,8 +20,15 @@ var (
func RunShell(options ShellOptions) {
+ sort.Slice(Commands, func(i, j int) bool {
+ return strings.Compare(Commands[i].Name(), Commands[j].Name()) < 0
+ })
+
line = liner.NewLiner()
defer line.Close()
+ grace.OnInterrupt(func() {
+ line.Close()
+ })
line.SetCtrlCAborts(true)
@@ -46,51 +53,57 @@ func RunShell(options ShellOptions) {
return
}
- cmds := reg.FindAllString(cmd, -1)
- if len(cmds) == 0 {
- continue
- } else {
- line.AppendHistory(cmd)
+ for _, c := range strings.Split(cmd, ";") {
+ if processEachCmd(reg, c, commandEnv) {
+ return
+ }
+ }
+ }
+}
- args := make([]string, len(cmds[1:]))
+func processEachCmd(reg *regexp.Regexp, cmd string, commandEnv *CommandEnv) bool {
+ cmds := reg.FindAllString(cmd, -1)
+ if len(cmds) == 0 {
+ return false
+ } else {
+ line.AppendHistory(cmd)
- for i := range args {
- args[i] = strings.Trim(string(cmds[1+i]), "\"'")
- }
+ args := make([]string, len(cmds[1:]))
- cmd := strings.ToLower(cmds[0])
- if cmd == "help" || cmd == "?" {
- printHelp(cmds)
- } else if cmd == "exit" || cmd == "quit" {
- return
- } else {
- foundCommand := false
- for _, c := range Commands {
- if c.Name() == cmd {
- if err := c.Do(args, commandEnv, os.Stdout); err != nil {
- fmt.Fprintf(os.Stderr, "error: %v\n", err)
- }
- foundCommand = true
+ for i := range args {
+ args[i] = strings.Trim(string(cmds[1+i]), "\"'")
+ }
+
+ cmd := cmds[0]
+ if cmd == "help" || cmd == "?" {
+ printHelp(cmds)
+ } else if cmd == "exit" || cmd == "quit" {
+ return true
+ } else {
+ foundCommand := false
+ for _, c := range Commands {
+ if c.Name() == cmd || c.Name() == "fs."+cmd {
+ if err := c.Do(args, commandEnv, os.Stdout); err != nil {
+ fmt.Fprintf(os.Stderr, "error: %v\n", err)
}
- }
- if !foundCommand {
- fmt.Fprintf(os.Stderr, "unknown command: %v\n", cmd)
+ foundCommand = true
}
}
-
+ if !foundCommand {
+ fmt.Fprintf(os.Stderr, "unknown command: %v\n", cmd)
+ }
}
+
}
+ return false
}
func printGenericHelp() {
msg :=
- `Type: "help <command>" for help on <command>
+ `Type: "help <command>" for help on <command>. Most commands support "<command> -h" also for options.
`
fmt.Print(msg)
- sort.Slice(Commands, func(i, j int) bool {
- return strings.Compare(Commands[i].Name(), Commands[j].Name()) < 0
- })
for _, c := range Commands {
helpTexts := strings.SplitN(c.Help(), "\n", 2)
fmt.Printf(" %-30s\t# %s \n", c.Name(), helpTexts[0])
@@ -106,10 +119,6 @@ func printHelp(cmds []string) {
} else {
cmd := strings.ToLower(args[0])
- sort.Slice(Commands, func(i, j int) bool {
- return strings.Compare(Commands[i].Name(), Commands[j].Name()) < 0
- })
-
for _, c := range Commands {
if c.Name() == cmd {
fmt.Printf(" %s\t# %s\n", c.Name(), c.Help())