seaweedfs/weed-fs/src/cmd/weed/shell.go

55 lines
849 B
Go
Raw Normal View History

2012-08-24 03:56:09 +00:00
package main
import (
"bufio"
"os"
"fmt"
2012-08-24 03:56:09 +00:00
)
func init() {
cmdShell.Run = runShell // break init cycle
2012-08-24 03:56:09 +00:00
}
var cmdShell = &Command{
UsageLine: "shell",
Short: "run interactive commands, now just echo",
Long: `run interactive commands.
2012-08-24 03:56:09 +00:00
`,
}
var (
)
2012-08-24 03:56:09 +00:00
func runShell(command *Command, args []string) bool {
r := bufio.NewReader(os.Stdin)
o := bufio.NewWriter(os.Stdout)
e := bufio.NewWriter(os.Stderr)
prompt := func () {
o.WriteString("> ")
o.Flush()
};
readLine := func () string {
ret, err := r.ReadString('\n')
if err != nil {
fmt.Fprint(e,err);
os.Exit(1)
}
return ret
}
execCmd := func (cmd string) int {
if cmd != "" {
o.WriteString(cmd)
}
return 0
}
2012-08-24 03:56:09 +00:00
cmd := ""
for {
prompt()
cmd = readLine()
execCmd(cmd)
}
return true
2012-08-24 03:56:09 +00:00
}