utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBotConfig

func GetBotConfig(c *cli.Command, tokenOverride string) (*cfg.BotConfig, error)

GetBotConfig determines which bot configuration to use Priority: 1) --token flag, 2) --bot flag, 3) current from config

func GetBotConfigFromContext

func GetBotConfigFromContext(ctx context.Context) *cfg.BotConfig

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

func GetTokenFromContext(ctx context.Context) string

GetTokenFromContext retrieves token from context

func HandleError

func HandleError(err error)

HandleError handles an error and exits if it's a CLIError

func IsCLIError

func IsCLIError(err error) bool

IsCLIError checks if an error is a CLIError

func PrintError

func PrintError(err error)

PrintError prints an error without exiting

func ReconstructJSON added in v1.1.0

func ReconstructJSON(initial string, args []string, target interface{}) (string, bool)

ReconstructJSON attempts to fix a JSON string that might have been split by the shell by appending the remaining arguments. Returns the reconstructed JSON string and true if successful, or empty string and false if not.

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
	Quiet        bool   // Suppress status messages
}

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

type CLIError struct {
	Message string
	Code    ExitCode
	Cause   error
}

CLIError is the base error type for CLI errors

func ConfigError

func ConfigError(message string) *CLIError

ConfigError creates a configuration error

func ConfigErrorf

func ConfigErrorf(format string, args ...interface{}) *CLIError

ConfigErrorf creates a formatted configuration error

func DiscordError

func DiscordError(message string) *CLIError

DiscordError creates a Discord API error

func DiscordErrorf

func DiscordErrorf(format string, args ...interface{}) *CLIError

DiscordErrorf creates a formatted Discord API error

func NewError

func NewError(message string, code ExitCode) *CLIError

NewError creates a new CLIError

func NewErrorWithCause

func NewErrorWithCause(message string, code ExitCode, cause error) *CLIError

NewErrorWithCause creates a new CLIError with a cause

func NotFoundError

func NotFoundError(resource string) *CLIError

NotFoundError creates a not found error

func NotFoundErrorf

func NotFoundErrorf(format string, args ...interface{}) *CLIError

NotFoundErrorf creates a formatted not found error

func ValidationError

func ValidationError(message string) *CLIError

ValidationError creates a validation error

func ValidationErrorf

func ValidationErrorf(format string, args ...interface{}) *CLIError

ValidationErrorf creates a formatted validation error

func WrapError

func WrapError(err error, message string, code ExitCode) *CLIError

WrapError wraps an error with a CLIError

func (*CLIError) Error

func (e *CLIError) Error() string

Error implements the error interface

func (*CLIError) Exit

func (e *CLIError) Exit()

Exit exits the application with the appropriate exit code

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

Unwrap returns the underlying 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

func GetExitCode(err error) ExitCode

GetExitCode gets the exit code from an error

Jump to

Keyboard shortcuts

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