utils

package
v0.99.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package utils provides shared CLI utility functions.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var ErrConfirmationRequired = errors.New("confirmation required")

ErrConfirmationRequired is returned when a destructive command needs --yes and input is disabled.

Functions

func Confirm

func Confirm(cmd *cobra.Command, prompt string) error

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

func ErrorObject(err error) map[string]any

ErrorObject returns the stderr error object for err.

func ExitCode

func ExitCode(err error) int

ExitCode maps err onto the frozen CLI exit codes.

func IsJSON

func IsJSON(cmd *cobra.Command) bool

IsJSON reports whether cmd requested JSON output. The flag may be local or inherited from a parent persistent flag.

func NewClient

func NewClient(cmd *cobra.Command) (*client.Client, error)

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

func NewPublicClient(cmd *cobra.Command) (*client.Client, error)

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

func NoInput(cmd *cobra.Command) bool

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

func Normalize(err error) error

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

func Print(cmd *cobra.Command, data, page any) error

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

func PrintError(w io.Writer, jsonMode bool, err error) error

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

func ResolveServerURL(cmd *cobra.Command) (string, error)

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

func ValidateOutput(cmd *cobra.Command, _ []string) error

ValidateOutput rejects --output values other than table and json.

func WriteEnvelope

func WriteEnvelope(w io.Writer, data, page any) error

WriteEnvelope writes {"data": ...} and page when page is non-nil.

func WritePlain

func WritePlain(w io.Writer, v any) error

WritePlain writes a line-oriented view of v for table mode.

func Yes

func Yes(cmd *cobra.Command) bool

Yes reports whether --yes / -y is set on cmd or an ancestor.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL