Documentation
¶
Overview ¶
Package cmd provides CLI command implementations with user-friendly error handling.
Index ¶
- Variables
- func Execute(ctx context.Context) error
- func ExecuteCommand(cmd *cobra.Command, f *Factory) error
- func FormatError(err error) error
- func NewAuthCmd(f *Factory) *cobra.Command
- func NewCompletionCmd() *cobra.Command
- func NewConfigCmd(f *Factory) *cobra.Command
- func NewHelpJSONCmd() *cobra.Command
- func NewInsightsCmd(f *Factory) *cobra.Command
- func NewIntentsCmd() *cobra.Command
- func NewListCommand[T any](cfg ListConfig[T], getClient func(context.Context) (*api.Client, error)) *cobra.Command
- func NewLocationsCmd(f *Factory) *cobra.Command
- func NewOEmbedCmd(f *Factory) *cobra.Command
- func NewPostsCmd(f *Factory) *cobra.Command
- func NewRateLimitCmd(f *Factory) *cobra.Command
- func NewRepliesCmd(f *Factory) *cobra.Command
- func NewRootCmd(f *Factory) *cobra.Command
- func NewSearchCmd(f *Factory) *cobra.Command
- func NewUsersCmd(f *Factory) *cobra.Command
- func NewUsersMeCmd(f *Factory) *cobra.Command
- func NewVersionCmd() *cobra.Command
- func NewWebhooksCmd(f *Factory) *cobra.Command
- func ValidateHTTPSURL(rawURL, fieldName string) error
- func WrapError(context string, err error) error
- func WriteErrorTo(ctx context.Context, w io.Writer, err error)
- type Factory
- type FactoryOptions
- type ListConfig
- type ListResult
- type RootOptions
- type UserFriendlyError
Constants ¶
This section is empty.
Variables ¶
var ( // Version information (set via ldflags) Version = "dev" Commit = "none" BuildDate = "unknown" )
Functions ¶
func ExecuteCommand ¶
ExecuteCommand runs a prepared command and handles formatted errors.
func FormatError ¶
FormatError converts API errors and common errors into user-friendly messages with actionable suggestions. This should be called on errors before returning them to the user.
func NewAuthCmd ¶
NewAuthCmd builds the auth command group.
func NewCompletionCmd ¶
func NewConfigCmd ¶
NewConfigCmd builds the config command group.
func NewHelpJSONCmd ¶ added in v1.4.1
func NewInsightsCmd ¶
NewInsightsCmd builds the insights command group.
func NewIntentsCmd ¶ added in v1.4.8
NewIntentsCmd builds the web intents command group.
func NewListCommand ¶
func NewListCommand[T any](cfg ListConfig[T], getClient func(context.Context) (*api.Client, error)) *cobra.Command
NewListCommand creates a new list command using the provided configuration
func NewLocationsCmd ¶
NewLocationsCmd builds the locations command group.
func NewOEmbedCmd ¶ added in v1.4.8
NewOEmbedCmd builds the oembed command.
func NewPostsCmd ¶
NewPostsCmd builds the posts command group.
func NewRateLimitCmd ¶
NewRateLimitCmd builds the ratelimit command group.
func NewRepliesCmd ¶
NewRepliesCmd builds the replies command group.
func NewRootCmd ¶
NewRootCmd constructs the root command and wires subcommands.
func NewSearchCmd ¶
NewSearchCmd builds the search command.
func NewUsersCmd ¶
NewUsersCmd builds the users command group.
func NewUsersMeCmd ¶
NewUsersMeCmd builds a top-level alias for "users me".
func NewWebhooksCmd ¶
NewWebhooksCmd builds the webhooks command group.
func ValidateHTTPSURL ¶
ValidateHTTPSURL validates that a URL uses HTTPS protocol. Returns a UserFriendlyError if validation fails.
Types ¶
type Factory ¶
type Factory struct {
IO *iocontext.IO
Config *config.Config
Store func() (secrets.Store, error)
NewClient func(accessToken string, cfg *api.Config) (*api.Client, error)
Output outfmt.Format
ColorMode outfmt.ColorMode
Debug bool
Account string
// contains filtered or unexported fields
}
Factory provides shared dependencies and helpers for commands.
func NewFactory ¶
func NewFactory(ctx context.Context, opts FactoryOptions) (*Factory, error)
NewFactory creates a new Factory with defaults.
func (*Factory) ActiveCredentials ¶ added in v1.4.1
ActiveCredentials returns the stored credentials for the active account. This is useful for avoiding extra API calls (e.g. GetMe) when we already have stable identifiers like user_id.
type FactoryOptions ¶
type FactoryOptions struct {
IO *iocontext.IO
Config *config.Config
Store func() (secrets.Store, error)
NewClient func(accessToken string, cfg *api.Config) (*api.Client, error)
}
FactoryOptions allows overriding factory dependencies (mainly for tests).
type ListConfig ¶
type ListConfig[T any] struct { Use string Short string Long string Example string Headers []string RowFunc func(T) []string ColumnTypes []outfmt.ColumnType EmptyMessage string // Fetch function - called with cursor and limit Fetch func(ctx context.Context, client *api.Client, cursor string, limit int) (ListResult[T], error) }
ListConfig is a generic struct for configuring list commands
type ListResult ¶
ListResult is a generic struct for paginated list results
type RootOptions ¶
type RootOptions struct {
Account string
Output string
JSON bool
Color string
NoColor bool
Debug bool
Query string
Yes bool
NoPrompt bool
}
RootOptions captures global flags.
type UserFriendlyError ¶
UserFriendlyError wraps an error with a user-friendly message and optional suggestion.
func (*UserFriendlyError) Error ¶
func (e *UserFriendlyError) Error() string
func (*UserFriendlyError) Unwrap ¶
func (e *UserFriendlyError) Unwrap() error