Documentation
¶
Index ¶
- func GetBotConfig(c *cli.Command, tokenOverride string) (*cfg.BotConfig, error)
- func GetBotConfigFromContext(ctx context.Context) *cfg.BotConfig
- func GetClientFromContext(ctx context.Context) *discord.DiscordClient
- func GetOutputFormatFromContext(ctx context.Context) dprint.OutputFormat
- func GetTokenFromContext(ctx context.Context) string
- func HandleError(err error)
- func IsCLIError(err error) bool
- func PrintError(err error)
- func WithCLIContext(ctx context.Context, cliCtx *CLIContext) context.Context
- type CLIContext
- type CLIError
- func ConfigError(message string) *CLIError
- func ConfigErrorf(format string, args ...interface{}) *CLIError
- func DiscordError(message string) *CLIError
- func DiscordErrorf(format string, args ...interface{}) *CLIError
- func NewError(message string, code ExitCode) *CLIError
- func NewErrorWithCause(message string, code ExitCode, cause error) *CLIError
- func NotFoundError(resource string) *CLIError
- func NotFoundErrorf(format string, args ...interface{}) *CLIError
- func ValidationError(message string) *CLIError
- func ValidationErrorf(format string, args ...interface{}) *CLIError
- func WrapError(err error, message string, code ExitCode) *CLIError
- type ExitCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBotConfig ¶
GetBotConfig determines which bot configuration to use Priority: 1) --token flag, 2) --bot flag, 3) current from config
func GetBotConfigFromContext ¶
GetBotConfigFromContext retrieves bot config from context
func GetClientFromContext ¶
func GetClientFromContext(ctx context.Context) *discord.DiscordClient
GetClientFromContext retrieves Discord client from context
func GetOutputFormatFromContext ¶
func GetOutputFormatFromContext(ctx context.Context) dprint.OutputFormat
GetOutputFormatFromContext retrieves output format from context
func GetTokenFromContext ¶
GetTokenFromContext retrieves token from context
func HandleError ¶
func HandleError(err error)
HandleError handles an error and exits if it's a CLIError
func WithCLIContext ¶
func WithCLIContext(ctx context.Context, cliCtx *CLIContext) context.Context
WithCLIContext adds CLIContext to a standard context
Types ¶
type CLIContext ¶
type CLIContext struct {
OutputFormat dprint.OutputFormat
BotConfig *cfg.BotConfig
Client *discord.DiscordClient
Token string // Direct token override
}
CLIContext holds all the shared context for CLI commands
func NewCLIContext ¶
func NewCLIContext(c *cli.Command) (*CLIContext, error)
NewCLIContext creates a CLIContext from urfave/cli context
func (*CLIContext) Close ¶
func (ctx *CLIContext) Close()
Close cleans up resources (like Discord client connection)
func (*CLIContext) GetOutputManager ¶
func (ctx *CLIContext) GetOutputManager() *dprint.OutputManager
GetOutputManager creates an OutputManager from CLI context
type CLIError ¶
CLIError is the base error type for CLI errors
func ConfigError ¶
ConfigError creates a configuration error
func ConfigErrorf ¶
ConfigErrorf creates a formatted configuration error
func DiscordError ¶
DiscordError creates a Discord API error
func DiscordErrorf ¶
DiscordErrorf creates a formatted Discord API error
func NewErrorWithCause ¶
NewErrorWithCause creates a new CLIError with a cause
func NotFoundError ¶
NotFoundError creates a not found error
func NotFoundErrorf ¶
NotFoundErrorf creates a formatted not found error
func ValidationError ¶
ValidationError creates a validation error
func ValidationErrorf ¶
ValidationErrorf creates a formatted validation error
type ExitCode ¶
type ExitCode int
ExitCode represents the exit code for the application
const ( // ExitSuccess indicates successful execution ExitSuccess ExitCode = 0 // ExitError indicates a general error ExitError ExitCode = 1 // ExitConfigError indicates a configuration error ExitConfigError ExitCode = 2 // ExitDiscordError indicates a Discord API error ExitDiscordError ExitCode = 3 // ExitValidationError indicates a validation error ExitValidationError ExitCode = 4 // ExitNotFound indicates a resource was not found ExitNotFound ExitCode = 5 )
func GetExitCode ¶
GetExitCode gets the exit code from an error