rename from cmd to weed for easier "go build"

This commit is contained in:
Chris Lu
2013-02-10 04:05:28 -08:00
parent 37a1a70cc3
commit d4e5a22e53
9 changed files with 0 additions and 0 deletions

53
go/weed/shell.go Normal file
View File

@@ -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
}