Save the shell state in the state store so it can be retrieved by the next call in the chain
(ctx context.Context, st ShellState)
| 306 | // Save the shell state in the state store so it can be retrieved by the |
| 307 | // next call in the chain |
| 308 | func (h *shellCallHandler) Save(ctx context.Context, st ShellState) error { |
| 309 | if st.Key != "" { |
| 310 | // Replace instead of mutate otherwise it's harder to manage |
| 311 | // when it's saved in a var. |
| 312 | defer h.state.Delete(ctx, st.Key) |
| 313 | } |
| 314 | nkey := h.state.Store(st) |
| 315 | w := interp.HandlerCtx(ctx).Stdout |
| 316 | |
| 317 | if debugFlag && h.Debug() { |
| 318 | slog := slog.SpanLogger(ctx, InstrumentationLibrary) |
| 319 | slog.Debug("saving state", spreadDebugArgs(&st, "newKey", nkey)...) |
| 320 | } |
| 321 | |
| 322 | // Writing a state to the handler's stdout will resolve the state if it's |
| 323 | // the last one in the chain, so this could return an API error, for example. |
| 324 | _, err := w.Write([]byte(newStateToken(nkey))) |
| 325 | return err |
| 326 | } |
| 327 | |
| 328 | // Function returns the last function in the chain, if not empty |
| 329 | func (st ShellState) Function() FunctionCall { |
no test coverage detected