Documentation
¶
Overview ¶
Package cli provides the command-line interface for aperturecli.
Index ¶
- Constants
- Variables
- func ErrorKind(err error) string
- func ExitCode(err error) int
- func NewHealthCmd() *cobra.Command
- func NewInfoCmd() *cobra.Command
- func NewMCPCmd() *cobra.Command
- func NewRootCmd() *cobra.Command
- func NewSchemaCmd() *cobra.Command
- func NewServicesCmd() *cobra.Command
- func NewStatsCmd() *cobra.Command
- func NewTokensCmd() *cobra.Command
- func NewTransactionsCmd() *cobra.Command
- func WriteErrorJSON(w io.Writer, err error)
- type ArgSchema
- type CLIError
- func ErrAuthWrap(inner error) *CLIError
- func ErrConnectionWrap(inner error) *CLIError
- func ErrDryRunPassedNew() *CLIError
- func ErrInvalidArgsf(format string, args ...any) *CLIError
- func ErrNotFoundf(format string, args ...any) *CLIError
- func NewCLIError(code int, kind, message string) *CLIError
- func WrapCLIError(code int, kind string, inner error) *CLIError
- type CommandSchema
- type FlagSchema
Constants ¶
const ( // ExitSuccess indicates the command completed successfully. ExitSuccess = 0 // ExitGeneralError indicates an unclassified error. ExitGeneralError = 1 // ExitInvalidArgs indicates invalid arguments or validation failure. ExitInvalidArgs = 2 // ExitConnectionError indicates a gRPC connection failure. ExitConnectionError = 3 // ExitAuthFailure indicates a macaroon authentication failure. ExitAuthFailure = 4 // ExitNotFound indicates a requested resource was not found. ExitNotFound = 5 // ExitDryRunPassed indicates a dry-run completed successfully // with no action taken. ExitDryRunPassed = 10 )
Exit codes for aperturecli. These are semantic exit codes that agents can parse for control flow, going beyond the typical 0/1 binary.
Variables ¶
var Version = "dev"
Version is set at build time via -ldflags.
Functions ¶
func ErrorKind ¶
ErrorKind extracts the machine-readable kind string from an error. If the error is not a CLIError, "general_error" is returned.
func ExitCode ¶
ExitCode extracts the exit code from an error. If the error is a CLIError, its Code field is returned. Otherwise 1 (general error) is returned.
func NewHealthCmd ¶
NewHealthCmd creates the health subcommand that checks server health.
func NewInfoCmd ¶
NewInfoCmd creates the info subcommand that displays Aperture server information.
func NewRootCmd ¶
NewRootCmd creates the root aperturecli command with all subcommands registered.
func NewSchemaCmd ¶
NewSchemaCmd creates the schema introspection subcommand. It allows agents to discover the CLI's commands, flags, and types at runtime without parsing --help text.
func NewServicesCmd ¶
NewServicesCmd creates the services parent command with list, create, update, and delete subcommands.
func NewStatsCmd ¶
NewStatsCmd creates the stats subcommand that displays revenue statistics.
func NewTokensCmd ¶
NewTokensCmd creates the tokens parent command with list and revoke subcommands.
func NewTransactionsCmd ¶
NewTransactionsCmd creates the transactions parent command.
func WriteErrorJSON ¶
WriteErrorJSON writes a structured JSON error object to the given writer. This is used by the main entrypoint to emit machine-readable errors on stderr.
Types ¶
type ArgSchema ¶
type ArgSchema struct {
// Name is the argument name.
Name string `json:"name"`
// Required indicates whether the argument is mandatory.
Required bool `json:"required"`
// Description explains the argument.
Description string `json:"description"`
}
ArgSchema describes a positional argument.
type CLIError ¶
type CLIError struct {
// Code is the process exit code.
Code int
// Kind is a machine-readable error classifier such as
// "invalid_args" or "connection_error".
Kind string
// Message is the human-readable error description.
Message string
// Inner is the wrapped cause, if any.
Inner error
}
CLIError is a structured error that carries a semantic exit code and a machine-readable error kind string. The CLI uses this to emit structured JSON error objects on stderr and return the appropriate exit code.
func ErrAuthWrap ¶
ErrAuthWrap wraps an authentication error with the auth_failure exit code.
func ErrConnectionWrap ¶
ErrConnectionWrap wraps a connection error with the connection_error exit code.
func ErrDryRunPassedNew ¶
func ErrDryRunPassedNew() *CLIError
ErrDryRunPassedNew creates a dry-run-passed indicator. This is not a real error; it signals that the dry-run preview completed successfully with no mutations.
func ErrInvalidArgsf ¶
ErrInvalidArgsf creates an invalid-arguments error with a formatted message.
func ErrNotFoundf ¶
ErrNotFoundf creates a not-found error with a formatted message.
func NewCLIError ¶
NewCLIError creates a new CLIError with the given code, kind, and message.
func WrapCLIError ¶
WrapCLIError creates a new CLIError that wraps an existing error.
type CommandSchema ¶
type CommandSchema struct {
// Name is the command name (e.g. "services").
Name string `json:"name"`
// FullPath is the fully qualified command path
// (e.g. "aperturecli services list").
FullPath string `json:"full_path"`
// Description is the short description of the command.
Description string `json:"description"`
// LongDescription is the detailed description, if available.
LongDescription string `json:"long_description,omitempty"`
// Args describes the positional arguments.
Args []ArgSchema `json:"args,omitempty"`
// Flags lists all flags accepted by this command.
Flags []FlagSchema `json:"flags,omitempty"`
// Subcommands lists child commands, if any.
Subcommands []CommandSchema `json:"subcommands,omitempty"`
// ExitCodes documents the semantic exit codes.
ExitCodes map[int]string `json:"exit_codes,omitempty"`
}
CommandSchema is the machine-readable schema for a CLI command, designed for agent introspection via aperturecli schema.
type FlagSchema ¶
type FlagSchema struct {
// Name is the long flag name (without --).
Name string `json:"name"`
// Short is the single-character shorthand, if any.
Short string `json:"short,omitempty"`
// Type is the value type (string, bool, int, etc.).
Type string `json:"type"`
// Default is the default value as a string.
Default string `json:"default,omitempty"`
// Description explains the flag.
Description string `json:"description"`
}
FlagSchema describes a CLI flag.