From cbe4e705db52934a09dfec767a373e903dab859d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 14 May 2024 13:14:21 +0530 Subject: [PATCH] Allow at commands to specialize response handling --- tools/cmd/at/main.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tools/cmd/at/main.go b/tools/cmd/at/main.go index c86066815..4201b1fd8 100644 --- a/tools/cmd/at/main.go +++ b/tools/cmd/at/main.go @@ -189,6 +189,7 @@ type rc_io_data struct { serializer serializer_func on_key_event func(lp *loop.Loop, ke *loop.KeyEvent) error string_response_is_err bool + handle_response func(data []byte) error timeout time.Duration multiple_payload_generator func(io_data *rc_io_data) (bool, error) @@ -260,19 +261,9 @@ func send_rc_command(io_data *rc_io_data) (err error) { return } var response *Response - if global_options.to_network == "" { - response, err = get_response(do_tty_io, io_data) - if err != nil { - return - } - } else { - response, err = get_response(do_socket_io, io_data) - if err != nil { - return - } - } + response, err = get_response(utils.IfElse(global_options.to_network == "", do_tty_io, do_socket_io), io_data) if err != nil || response == nil { - return err + return } if !response.Ok { if response.Traceback != "" { @@ -280,6 +271,9 @@ func send_rc_command(io_data *rc_io_data) (err error) { } return fmt.Errorf("%s", response.Error) } + if io_data.handle_response != nil { + return io_data.handle_response(utils.UnsafeStringToBytes(response.Data.as_str)) + } if response.Data.is_string && io_data.string_response_is_err { return fmt.Errorf("%s", response.Data.as_str) }