diff options
| author | Chris Lu <chris.lu@gmail.com> | 2013-02-10 03:09:26 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2013-02-10 03:09:26 -0800 |
| commit | cb4e8ec16b5c204718f1efdc1731f1bdd5698ff3 (patch) | |
| tree | 47f27040c3d80e6849932bf2acf54b68c930f72b /src/weed/shell.go | |
| parent | d3b267bac27018b7f70dfec7c258d0556fff4c14 (diff) | |
| download | seaweedfs-cb4e8ec16b5c204718f1efdc1731f1bdd5698ff3.tar.xz seaweedfs-cb4e8ec16b5c204718f1efdc1731f1bdd5698ff3.zip | |
re-organize code directory structure
Diffstat (limited to 'src/weed/shell.go')
| -rw-r--r-- | src/weed/shell.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/weed/shell.go b/src/weed/shell.go new file mode 100644 index 000000000..daf0b7e1f --- /dev/null +++ b/src/weed/shell.go @@ -0,0 +1,53 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func init() { + cmdShell.Run = runShell // break init cycle +} + +var cmdShell = &Command{ + UsageLine: "shell", + Short: "run interactive commands, now just echo", + Long: `run interactive commands. + + `, +} + +var () + +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 + } + + cmd := "" + for { + prompt() + cmd = readLine() + execCmd(cmd) + } + return true +} |
