|
|
@ -45,40 +45,49 @@ 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 || c.Name() == "fs."+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 := strings.ToLower(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() { |
|
|
|