Documentation
¶
Overview ¶
Package globalwait provides a global --wait mechanism for ionosctl. When --wait is set, it captures the href from the command's API response, then polls that href until the resource reaches a terminal ready state.
This package intentionally has no dependency on the table package. The Rerenderable interface is satisfied by *table.Table implicitly, and wiring is done in commands/root.go via the table.BeforeRender hook.
Index ¶
- Constants
- func HandleBeforeRender(sourceData any, visibleCols []string, r Rerenderable) bool
- func MarkDone()
- func Reset()
- func WaitAndRerender(stderr, stdout io.Writer, creds AuthCreds, quiet bool) error
- func WaitForAvailable(w io.Writer, token, username, password string) error
- func WrapTransport(hc *http.Client)
- type AuthCreds
- type Rerenderable
- type Waiter
- func (w *Waiter) HandleBeforeRender(sourceData any, visibleCols []string, r Rerenderable) bool
- func (w *Waiter) MarkDone()
- func (w *Waiter) Reset()
- func (w *Waiter) WaitAndRerender(stderr, stdout io.Writer, creds AuthCreds, quiet bool) error
- func (w *Waiter) WaitForAvailable(wr io.Writer, token, username, password string) error
- func (w *Waiter) WrapTransport(hc *http.Client)
Constants ¶
const ProgressTpl = `{{ etime . }} {{ "Waiting" }}{{ cycle . "." ".." "..." "...."}}`
ProgressTpl is the progress bar template used for --wait polling.
Variables ¶
This section is empty.
Functions ¶
func HandleBeforeRender ¶
func HandleBeforeRender(sourceData any, visibleCols []string, r Rerenderable) bool
HandleBeforeRender processes table output for --wait on the default Waiter.
func MarkDone ¶
func MarkDone()
MarkDone signals that all waiting has been handled inline by the command.
func WaitAndRerender ¶
WaitAndRerender polls and re-renders on the default Waiter.
func WaitForAvailable ¶
WaitForAvailable polls the captured href on the default Waiter.
func WrapTransport ¶
WrapTransport wraps an http.Client's Transport on the default Waiter.
Types ¶
type AuthCreds ¶
type AuthCreds struct {
Token, Username, Password string
}
AuthCreds holds authentication credentials for polling requests.
type Rerenderable ¶
type Rerenderable interface {
Extract(sourceData any) error
Render(visibleCols []string) (string, error)
}
Rerenderable can re-render its output with fresh source data. Implemented by *table.Table without requiring an import of that package.
type Waiter ¶
type Waiter struct {
// contains filtered or unexported fields
}
Waiter holds all captured state for a single --wait lifecycle. Use defaultWaiter (via package-level functions) for normal CLI operation, or create a local instance for isolated testing.
func (*Waiter) HandleBeforeRender ¶
func (w *Waiter) HandleBeforeRender(sourceData any, visibleCols []string, r Rerenderable) bool
HandleBeforeRender processes table output for --wait. Returns true to render normally, false to suppress (output will be re-rendered after wait completes). Called from the table.BeforeRender hook adapter in commands/root.go.
func (*Waiter) MarkDone ¶
func (w *Waiter) MarkDone()
MarkDone signals that all waiting has been handled inline by the command. HandleBeforeRender will render normally, and WaitAndRerender will be a no-op. Used by commands that perform multiple mutating API calls and manage their own wait lifecycle (e.g. server create --promote-volume).
func (*Waiter) Reset ¶
func (w *Waiter) Reset()
Reset clears all captured state. Call between multiple mutating API calls within a single command to prevent mismatched state (e.g. server create followed by --promote-volume). Each call to captureRequestURL overwrites the request status URL but preserves the first resource href, so without Reset() the poller may poll a request status URL from call #2 while using a resource href from call #1.
func (*Waiter) WaitAndRerender ¶
WaitAndRerender polls until the resource is available, then re-renders output with fresh data showing the final state. Call after successful command execution when --wait is set. Progress and warnings are written to stderr; re-rendered output is written to stdout.
func (*Waiter) WaitForAvailable ¶
WaitForAvailable polls the captured href until the resource reaches a terminal ready state. It then walks up the resource hierarchy and polls each parent until AVAILABLE too. Progress output is written to wr (typically os.Stderr). Returns nil if no href was captured (command doesn't deal with API resources).
func (*Waiter) WrapTransport ¶
WrapTransport wraps an http.Client's Transport so that every response URL is captured for --wait polling. This makes delete/detach commands work across all SDK clients without per-command changes.