charmer

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: MIT Imports: 7 Imported by: 1

README

charmer

godoc

Boilerplate utilities for cobra & viper.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogger

func GetLogger(cmd *cobra.Command) *slog.Logger

GetLogger returns the logger from the command's context. If no logger was set, it returns slog.Default().

func SetDefaults

func SetDefaults(v *viper.Viper, args Arguments) error

SetDefaults sets up default values in viper.

func SetJSONLogger

func SetJSONLogger(cmd *cobra.Command, debug bool)

SetJSONLogger creates a slog.Logger with a slog.JSONHandler and adds it to the command's context. If debug is true, the handler's log level is set to slog.LevelDebug.

func SetLogger

func SetLogger(cmd *cobra.Command, logger *slog.Logger)

SetLogger adds a slog.Logger to the command's context.

func SetPersistentFlags

func SetPersistentFlags(cmd *cobra.Command, v *viper.Viper, args Arguments) error

SetPersistentFlags adds the arguments and their default values to a cobra.Command as PersistentFlags and binds them to viper.

func SetTextLogger

func SetTextLogger(cmd *cobra.Command, debug bool)

SetTextLogger creates a slog.Logger with a slog.TextHandler and adds it to the command's context. If debug is true, the handler's log level is set to slog.LevelDebug.

Types

type Argument

type Argument struct {
	Default any
	Help    string
}

type Arguments

type Arguments map[string]Argument

Jump to

Keyboard shortcuts

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