(deps commandDeps)
| 436 | } |
| 437 | |
| 438 | func newSessionWaitCommand(deps commandDeps) *cobra.Command { |
| 439 | return &cobra.Command{ |
| 440 | Use: "wait <id>", |
| 441 | Short: "Block until a session stops", |
| 442 | Example: ` # Block until a session emits its stopped event |
| 443 | agh session wait sess_1234`, |
| 444 | Args: exactOneNonBlankArg(), |
| 445 | RunE: func(cmd *cobra.Command, args []string) error { |
| 446 | client, err := clientFromDeps(deps) |
| 447 | if err != nil { |
| 448 | return err |
| 449 | } |
| 450 | |
| 451 | info, err := client.GetSession(cmd.Context(), args[0]) |
| 452 | if err != nil { |
| 453 | return err |
| 454 | } |
| 455 | if info.State != session.StateStopped { |
| 456 | err = client.StreamSessionEvents( |
| 457 | cmd.Context(), |
| 458 | args[0], |
| 459 | SessionEventQuery{}, |
| 460 | "", |
| 461 | func(event SSEEvent) error { |
| 462 | if event.Event == session.EventTypeSessionStopped { |
| 463 | return errStopSSE |
| 464 | } |
| 465 | return nil |
| 466 | }, |
| 467 | ) |
| 468 | if err != nil && !errors.Is(err, errStopSSE) { |
| 469 | return err |
| 470 | } |
| 471 | info, err = client.GetSession(cmd.Context(), args[0]) |
| 472 | if err != nil { |
| 473 | return err |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | return writeCommandOutput(cmd, sessionBundle(info, deps.now)) |
| 478 | }, |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | func newSessionPromptCommand(deps commandDeps) *cobra.Command { |
| 483 | var ( |
no test coverage detected