Documentation
¶
Overview ¶
Package utils provides shared CLI utility functions.
Index ¶
- Variables
- func Confirm(cmd *cobra.Command, prompt string) error
- func ErrorObject(err error) map[string]any
- func ExitCode(err error) int
- func IsJSON(cmd *cobra.Command) bool
- func NewClient(cmd *cobra.Command) (*client.Client, error)
- func NewPublicClient(cmd *cobra.Command) (*client.Client, error)
- func NoInput(cmd *cobra.Command) bool
- func Normalize(err error) error
- func Print(cmd *cobra.Command, data, page any) error
- func PrintError(w io.Writer, jsonMode bool, err error) error
- func ResolveServerURL(cmd *cobra.Command) (string, error)
- func ValidateOutput(cmd *cobra.Command, _ []string) error
- func WriteEnvelope(w io.Writer, data, page any) error
- func WritePlain(w io.Writer, v any) error
- func Yes(cmd *cobra.Command) bool
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = errors.New("cancelled")
ErrCancelled is returned when an operator declines a confirmation prompt. It is a CLI-only code and is not part of the MCP error vocabulary.
var ErrConfirmationRequired = errors.New("confirmation required")
ErrConfirmationRequired is returned when a destructive command needs --yes and input is disabled.
Functions ¶
func Confirm ¶
Confirm runs a yes/no prompt. --yes proceeds. No-input mode returns ErrConfirmationRequired without reading stdin. Any answer other than y returns ErrCancelled.
func ErrorObject ¶
ErrorObject returns the stderr error object for err.
func IsJSON ¶
IsJSON reports whether cmd requested JSON output. The flag may be local or inherited from a parent persistent flag.
func NewClient ¶
NewClient builds an API client from CLI flags, environment variables, and stored config. Server URL resolution order: --server-url, FLOWBOT_SERVER_URL, then stored server_url. Token resolution order: FLOWBOT_TOKEN, then stored token file.
func NewPublicClient ¶
NewPublicClient builds an API client that can call public endpoints without a token. Server URL resolution matches NewClient. Returns an error when no server URL is configured.
func NoInput ¶
NoInput reports whether prompts must not read stdin. --no-input forces that mode. A non-terminal stdin does too. A pseudo-terminal still counts as a terminal.
func Normalize ¶
Normalize converts API and cobra usage errors into domain errors so they share the MCP code table. Domain errors and confirmation sentinels pass through.
func Print ¶
Print writes the JSON success envelope when cmd is in JSON mode. Otherwise it writes a plain-text view of data. A value that is already a {data, page} object is not wrapped again. page is included only when non-nil.
func PrintError ¶
PrintError writes a failure to w. JSON mode writes the error envelope and leaves the caller responsible for an empty stdout. Table mode writes Error: plus the original error text.
func ResolveServerURL ¶
ResolveServerURL returns the Flowbot server URL from flags, env, or stored config. Resolution order: --server-url, FLOWBOT_SERVER_URL, then stored server_url.
func ValidateOutput ¶
ValidateOutput rejects --output values other than table and json.
func WriteEnvelope ¶
WriteEnvelope writes {"data": ...} and page when page is non-nil.
func WritePlain ¶
WritePlain writes a line-oriented view of v for table mode.
Types ¶
This section is empty.