executeCommandAndRespond dispatches a command.execute event to the registered handler and sends the result (or error) back via the RPC layer.
(requestID, commandName, command, args string)
| 881 | // executeCommandAndRespond dispatches a command.execute event to the registered handler |
| 882 | // and sends the result (or error) back via the RPC layer. |
| 883 | func (s *Session) executeCommandAndRespond(requestID, commandName, command, args string) { |
| 884 | ctx := context.Background() |
| 885 | handler, ok := s.getCommandHandler(commandName) |
| 886 | if !ok { |
| 887 | errMsg := fmt.Sprintf("Unknown command: %s", commandName) |
| 888 | s.RPC.Commands.HandlePendingCommand(ctx, &rpc.CommandsHandlePendingCommandRequest{ |
| 889 | RequestID: requestID, |
| 890 | Error: &errMsg, |
| 891 | }) |
| 892 | return |
| 893 | } |
| 894 | |
| 895 | cmdCtx := CommandContext{ |
| 896 | SessionID: s.SessionID, |
| 897 | Command: command, |
| 898 | CommandName: commandName, |
| 899 | Args: args, |
| 900 | } |
| 901 | |
| 902 | if err := handler(cmdCtx); err != nil { |
| 903 | errMsg := err.Error() |
| 904 | s.RPC.Commands.HandlePendingCommand(ctx, &rpc.CommandsHandlePendingCommandRequest{ |
| 905 | RequestID: requestID, |
| 906 | Error: &errMsg, |
| 907 | }) |
| 908 | return |
| 909 | } |
| 910 | |
| 911 | s.RPC.Commands.HandlePendingCommand(ctx, &rpc.CommandsHandlePendingCommandRequest{ |
| 912 | RequestID: requestID, |
| 913 | }) |
| 914 | } |
| 915 | |
| 916 | // registerElicitationHandler registers an elicitation handler for this session. |
| 917 | func (s *Session) registerElicitationHandler(handler ElicitationHandler) { |
no test coverage detected