change sock comm seperator and pass path to warrend
This commit is contained in:
parent
b71105e503
commit
f1e64b1227
|
@ -5,8 +5,8 @@ import (
|
|||
"github.com/dballard/warren/lib/warren"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
// "os"
|
||||
// "os/exec"
|
||||
// "time"
|
||||
)
|
||||
|
@ -36,8 +36,9 @@ func runRun(cmd *warren.Command, args ...string) {
|
|||
if err != nil {
|
||||
log.Fatal("Error connecting to warrend:", err)
|
||||
}
|
||||
|
||||
warren.WriteStringz(s, strings.Join(args, " "))
|
||||
dir, _ := os.Getwd()
|
||||
// pwd|arg1 arg2 arg3 ....
|
||||
warren.WriteStringz(s, dir+"|"+strings.Join(args, "|"))
|
||||
|
||||
resp, err := warren.ReadStringz(s)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ var regCmd = &SockCommand{
|
|||
}
|
||||
|
||||
// reg path [nickname]
|
||||
func regRun(cmd *SockCommand, c net.Conn, args ...string) {
|
||||
func regRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
|
||||
if (len(args) > 0 && args[0] == "help") || len(args) < 1 {
|
||||
warren.WriteStringz(c, cmd.Help)
|
||||
return
|
||||
|
|
|
@ -20,7 +20,7 @@ var statusCmd = &SockCommand{
|
|||
Run: statusRun,
|
||||
}
|
||||
|
||||
func statusRun(cmd *SockCommand, c net.Conn, args ...string) {
|
||||
func statusRun(cmd *SockCommand, c net.Conn, path string, args ...string) {
|
||||
if len(args) > 0 && args[0] == "help" {
|
||||
warren.WriteStringz(c, cmd.Help)
|
||||
return
|
||||
|
|
|
@ -16,7 +16,7 @@ var cmdSock net.Listener
|
|||
|
||||
type SockCommand struct {
|
||||
warren.Command
|
||||
Run func(cmd *SockCommand, c net.Conn, args ...string)
|
||||
Run func(cmd *SockCommand, c net.Conn, path string, args ...string)
|
||||
}
|
||||
|
||||
func (cmd *SockCommand) GetName() string {
|
||||
|
@ -27,12 +27,12 @@ func (cmd *SockCommand) GetSummary() string {
|
|||
return cmd.Summary
|
||||
}
|
||||
|
||||
func (cmd *SockCommand) Exec(c net.Conn, args []string) {
|
||||
func (cmd *SockCommand) Exec(c net.Conn, path string, args []string) {
|
||||
cmd.Flag.Usage = func() {
|
||||
// helpFunc(c, c.Name)
|
||||
}
|
||||
cmd.Flag.Parse(args)
|
||||
cmd.Run(cmd, c, cmd.Flag.Args()...)
|
||||
cmd.Run(cmd, c, path, cmd.Flag.Args()...)
|
||||
}
|
||||
|
||||
func sockCmdHandle(c net.Conn) {
|
||||
|
@ -47,18 +47,23 @@ func sockCmdHandle(c net.Conn) {
|
|||
fmt.Println("cmdHandle got command:", string(data))
|
||||
|
||||
// BAD: TODO: handle quotes "
|
||||
var args = strings.Split(data, " ")
|
||||
// path|arg1|arg2|...
|
||||
args := strings.Split(data, "|")
|
||||
if len(args) < 2 {
|
||||
warren.WriteStringz(c, "Format error")
|
||||
return
|
||||
}
|
||||
|
||||
// parse args
|
||||
var icmd = warren.GetCommand(args[0])
|
||||
var icmd = warren.GetCommand(args[1])
|
||||
// get and run cmd
|
||||
if icmd == nil {
|
||||
warren.WriteStringz(c, "Unknown command "+args[0])
|
||||
warren.WriteStringz(c, "Unknown command "+args[1])
|
||||
// usage ?
|
||||
|
||||
return
|
||||
}
|
||||
icmd.(*SockCommand).Exec(c, args[1:])
|
||||
icmd.(*SockCommand).Exec(c, args[0], args[2:])
|
||||
}
|
||||
|
||||
// determine if warrend is already running
|
||||
|
|
Loading…
Reference in New Issue