func echoCtrl(runner *protocol.CmdRunner, echoOn string) error { echoCtrl, err := protocol.NewEcho() if err != nil { return err } echoCtrl.Message = echoOn nmr, err := echoCtrl.EncodeEchoCtrl() if err != nil { return err } if err := runner.WriteReq(nmr); err != nil { return err } _, err = runner.ReadResp() if err != nil { return err } return nil }
func echoRunCmd(cmd *cobra.Command, args []string) { runner, err := getTargetCmdRunner() if err != nil { nmUsage(cmd, err) } defer runner.Conn.Close() echo, err := protocol.NewEcho() if err != nil { nmUsage(cmd, err) } if len(args) != 1 { nmUsage(cmd, nil) } echo.Message = args[0] nmr, err := echo.EncodeWriteRequest() if err != nil { nmUsage(cmd, err) } if err := runner.WriteReq(nmr); err != nil { nmUsage(cmd, err) } rsp, err := runner.ReadResp() if err != nil { nmUsage(cmd, err) } ersp, err := protocol.DecodeEchoResponse(rsp.Data) if err != nil { nmUsage(cmd, err) } fmt.Println(ersp.Response) }