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