# HG changeset patch # User telesto # Date 1418674511 -3600 # Mon Dec 15 21:15:11 2014 +0100 # Node ID c55fefa7a9a377b041615692e43583f4f541c971 # Parent 913280b646ff889bf3cfd53fd93d8687f2716618 removed lua command, its useless, and 'lua ...' is what i need diff --git a/cmd/hackurist/main.go b/cmd/hackurist/main.go --- a/cmd/hackurist/main.go +++ b/cmd/hackurist/main.go @@ -13,12 +13,10 @@ flag.PrintDefaults() } -var address = flag.String("a", "127.0.0.1:5000", "dfhack rpc server address") -var debug = flag.Bool("d", false, "print debug messages") - func main() { + address := flag.String("a", "127.0.0.1:5000", "dfhack rpc server address") + debug := flag.Bool("d", false, "print debug messages") help := flag.Bool("h", false, "help") - lua := flag.Bool("lua", false, "run lua command") flag.Parse() if *help { @@ -29,12 +27,8 @@ usage() os.Exit(2) } - var err error - if *lua { - err = runCommand() - } else { - err = runLuaCommand() - } + cmd := flag.Arg(0) + err := run(*address, cmd, flag.Args()[1:], *debug) if err != nil { log.Println(err) os.Exit(1) @@ -42,8 +36,8 @@ os.Exit(0) } -func runLuaCommand() error { - conn, err := hackurist.Dial(*address, *debug) +func run(address, cmd string, args []string, debug bool) error { + conn, err := hackurist.Dial(address, debug) if err != nil { return err } @@ -52,28 +46,10 @@ if err != nil { return err } - result, err := conn.RunLuaCommand(flag.Arg(0), flag.Arg(1), flag.Args()[2:]) + result, err := conn.RunCommand(cmd, args) fmt.Print(string(result)) if err != nil { return err } return nil } - -func runCommand() error { - conn, err := hackurist.Dial(*address, *debug) - if err != nil { - return err - } - defer conn.Close() - err = conn.ShakeHands() - if err != nil { - return err - } - result, err := conn.RunCommand(flag.Arg(0), flag.Args()[1:]) - fmt.Print(string(result)) - if err != nil { - return err - } - return nil -} diff --git a/hackurist.go b/hackurist.go --- a/hackurist.go +++ b/hackurist.go @@ -202,22 +202,6 @@ return response, nil } -// RunLuaCommand sends lua command to the server. -// It reads the response, processes it and returns the output -// ready for a text client. -func (c Conn) RunLuaCommand(module, fn string, args []string) ([]byte, error) { - protoCmd, err := proto.Marshal(&dfproto.CoreRunLuaRequest{Module: &module, - Function: &fn, Arguments: args}) - if err != nil { - return nil, fmt.Errorf("RunCommand: %s", err) - } - if err = c.write(protoCmd); err != nil { - return nil, fmt.Errorf("RunLuaCommand: %s", err) - } - - return nil, nil -} - // todo: timeout func (c Conn) write(b []byte) error { written, err := c.conn.Write(b)