cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvAuto = "auto"
	EnvLive = "live"
	EnvTest = "test"
)
View Source
const (
	ExitSuccess = iota
	ExitGeneric
	ExitUsage
	ExitValidation
	ExitAuthentication
	ExitForbidden
	ExitNotFound
	ExitConflict
	ExitRateLimited
	ExitNetwork
)
View Source
const DefaultProfile = "default"

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() (string, error)

func ConfigPath

func ConfigPath() (string, error)

func EnvFromAPIKey

func EnvFromAPIKey(key string) (string, bool)

func Execute

func Execute() int

func ExecuteWithArgs

func ExecuteWithArgs(args []string, out, errOut io.Writer) int

func ExitCodeForHTTPStatus

func ExitCodeForHTTPStatus(status int) int

func LatestAvailableVersion

func LatestAvailableVersion() (string, error)

func NewRootCommand

func NewRootCommand() *cobra.Command

func RedactAPIKey

func RedactAPIKey(key string) string

func RenderData

func RenderData(w io.Writer, contract Contract, data any) error

func RenderError

func RenderError(w io.Writer, contract Contract, err error) int

func SaveConfig

func SaveConfig(store ConfigStore) error

func SetBuildInfo

func SetBuildInfo(v, c, b string)

func SetOutput

func SetOutput(cmd *cobra.Command, out, errOut io.Writer)

func SetVersionInfo

func SetVersionInfo(v, c string)

SetVersionInfo is used by tests and build-time ldflags to override version metadata.

Types

type AuthSource

type AuthSource string
const (
	AuthSourceNone   AuthSource = "none"
	AuthSourceFlag   AuthSource = "flag"
	AuthSourceEnv    AuthSource = "env"
	AuthSourceConfig AuthSource = "config"
)

type CLIError

type CLIError struct {
	Envelope api.ApiErrorResponse
	Exit     int
	Status   int
	Hint     string
	DocsURL  string
	// contains filtered or unexported fields
}

func NewAPIError

func NewAPIError(status int, envelope api.ApiErrorResponse, hint, docsURL string) *CLIError

func NewLocalError

func NewLocalError(exit int, code, message, parameter, hint, docsURL string) *CLIError

func (*CLIError) Error

func (e *CLIError) Error() string

type ConfigStore

type ConfigStore struct {
	CurrentProfile string                  `toml:"current_profile,omitempty" json:"current_profile,omitempty"`
	Profiles       map[string]ProfileStore `toml:"profiles,omitempty" json:"profiles"`
}

func LoadConfig

func LoadConfig() (ConfigStore, error)

func NewConfigStore

func NewConfigStore() ConfigStore

type Contract

type Contract struct {
	OutputMode     OutputMode
	Quiet          bool
	NoColor        bool
	NonInteractive bool
	Debug          bool
	APIBase        string
	APIKey         string
	Profile        string
	Env            string
	RequestID      string
	IdempotencyKey string
}

type DescribeArg

type DescribeArg struct {
	Name        string `json:"name"`
	Required    bool   `json:"required"`
	Description string `json:"description,omitempty"`
}

type DescribeCommand

type DescribeCommand struct {
	Name                 string               `json:"name"`
	Path                 []string             `json:"path"`
	Use                  string               `json:"use"`
	Short                string               `json:"short,omitempty"`
	Args                 []DescribeArg        `json:"args"`
	Flags                []DescribeFlag       `json:"flags"`
	AcceptedInputFields  []DescribeInputField `json:"accepted_input_fields"`
	ExpectedOutputSchema any                  `json:"expected_output_schema,omitempty"`
	ExitCodes            []int                `json:"exit_codes"`
	Example              DescribeExample      `json:"example"`
}

type DescribeDocument

type DescribeDocument struct {
	SchemaVersion string                  `json:"schema_version"`
	GeneratedFrom DescribeGeneratedFrom   `json:"generated_from"`
	ExitCodes     []DescribeExitCode      `json:"exit_codes"`
	Commands      []DescribeCommand       `json:"commands"`
	OpenAPI       DescribeOpenAPISnapshot `json:"openapi"`
}

func BuildDescribeDocument

func BuildDescribeDocument(root *cobra.Command) (DescribeDocument, error)

type DescribeExample

type DescribeExample struct {
	Command string `json:"command"`
}

type DescribeExitCode

type DescribeExitCode struct {
	Code    int    `json:"code"`
	Meaning string `json:"meaning"`
}

type DescribeFlag

type DescribeFlag struct {
	Name        string `json:"name"`
	Shorthand   string `json:"shorthand,omitempty"`
	Type        string `json:"type"`
	Required    bool   `json:"required"`
	Default     string `json:"default,omitempty"`
	Description string `json:"description,omitempty"`
}

type DescribeGeneratedFrom

type DescribeGeneratedFrom struct {
	OpenAPI string `json:"openapi"`
	Cobra   string `json:"cobra"`
}

type DescribeInputField

type DescribeInputField struct {
	Name        string `json:"name"`
	Location    string `json:"location"`
	Required    bool   `json:"required"`
	Description string `json:"description,omitempty"`
	Schema      any    `json:"schema,omitempty"`
}

type DescribeOpenAPIOperation

type DescribeOpenAPIOperation struct {
	OperationID string               `json:"operation_id"`
	Method      string               `json:"method"`
	Path        string               `json:"path"`
	Tags        []string             `json:"tags,omitempty"`
	Summary     string               `json:"summary,omitempty"`
	Inputs      []DescribeInputField `json:"inputs"`
	Output      any                  `json:"output,omitempty"`
	ExitCodes   []int                `json:"exit_codes"`
}

type DescribeOpenAPISnapshot

type DescribeOpenAPISnapshot struct {
	Title      string                     `json:"title"`
	Version    string                     `json:"version"`
	Operations []DescribeOpenAPIOperation `json:"operations"`
}

type DoctorCheck

type DoctorCheck struct {
	Name     string `json:"name"`
	Status   string `json:"status"`
	Detail   string `json:"detail,omitempty"`
	ExitCode int    `json:"exit_code"`
}

type DoctorResult

type DoctorResult struct {
	Checks []DoctorCheck `json:"checks"`
}

type OutputMode

type OutputMode string
const (
	OutputHuman OutputMode = "human"
	OutputJSON  OutputMode = "json"
	OutputRaw   OutputMode = "raw"
)

func ResolveOutputMode

func ResolveOutputMode(jsonFlag, rawFlag, stdoutIsTTY bool) OutputMode

type ProfileStore

type ProfileStore struct {
	APIKey string `toml:"api_key,omitempty" json:"api_key,omitempty"`
}

type ResolvedAuth

type ResolvedAuth struct {
	APIKey   string     `json:"-"`
	Redacted string     `json:"api_key,omitempty"`
	Env      string     `json:"env"`
	Profile  string     `json:"profile,omitempty"`
	Source   AuthSource `json:"source"`
}

func ResolveAuth

func ResolveAuth(opts rootOptions) (ResolvedAuth, error)

type SilentExitError

type SilentExitError struct {
	Code int
}

func (SilentExitError) Error

func (e SilentExitError) Error() string

type UpgradeResult

type UpgradeResult struct {
	Status  string `json:"status"`
	Version string `json:"version,omitempty"`
	Path    string `json:"path,omitempty"`
	Reason  string `json:"reason,omitempty"`
}

func Upgrade

func Upgrade(ctx context.Context) (UpgradeResult, error)

type VersionInfo

type VersionInfo struct {
	Version         string `json:"version"`
	Commit          string `json:"commit"`
	BuiltAt         string `json:"built_at"`
	APIBase         string `json:"api_base"`
	LatestAvailable string `json:"latest_available"`
}

func BuildVersionInfo

func BuildVersionInfo(apiBase string) VersionInfo

Jump to

Keyboard shortcuts

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