util

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CSV     = "csv"
	DEFAULT = "default"
	LDIF    = "ldif"
	YAML    = "yaml"
)

Variables

View Source
var Logger = func() *logrus.Logger {
	l := logrus.New()
	l.SetLevel(logrus.WarnLevel)
	l.SetOutput(Stdout())
	l.SetFormatter(&logrus.JSONFormatter{
		DisableHTMLEscape: true,
		PrettyPrint:       true,
	})

	supererrors.RegisterCallback(func(err error) {
		l.SetOutput(Stderr())

		if l.Level >= logrus.DebugLevel {
			err = tracerr.Wrap(err)

			var frames []string
			for _, frame := range err.(tracerr.Error).StackTrace() {
				switch ctx := frame.String(); {

				case
					strings.Contains(ctx, "supererrors.Except"),
					strings.Contains(ctx, "runtime.main()"),
					strings.Contains(ctx, "runtime.goexit()"):

					continue

				default:
					frames = append(frames, frame.String())

				}
			}

			l.WithField("stack", frames).Fatalln(err)
		}

		l.SetFormatter(&logrus.TextFormatter{
			ForceColors:            IsColorEnabled(),
			DisableTimestamp:       true,
			DisableLevelTruncation: true,
		})
		l.Fatalln(err)
	})

	return l
}()

App logger (default format JSON).

Functions

func AskBool

func AskBool(cmd *cobra.Command, flagName string, args *[]string, opts ...survey.AskOpt) (bool, error)

func AskCommand

func AskCommand(cmd *cobra.Command, def *cobra.Command, opts ...survey.AskOpt) (*cobra.Command, error)

func AskLDAPDataInterchangeFormat

func AskLDAPDataInterchangeFormat(requests *ldif.LDIF, editor string) (bool, error)

func AskMultiline

func AskMultiline(cmd *cobra.Command, flagName string, args *[]string, opts ...survey.AskOpt) (bool, error)

func AskString

func AskString(cmd *cobra.Command, flagName string, args *[]string, password bool, def string, opts ...survey.AskOpt) (bool, error)

func AskStrings

func AskStrings(cmd *cobra.Command, flagName string, options, def []string, args *[]string, opts ...survey.AskOpt) (bool, error)

func CheckColors

func CheckColors(fn func(string, ...any) string, format string, a ...any) string

func Flush added in v1.0.2

func Flush(results attributes.Maps, requests *ldif.LDIF, format string, out io.Writer) error

func GetFieldsForBind

func GetFieldsForBind(bindParameters *auth.BindParameters, dialOptions *auth.DialOptions) logrus.Fields

func GetFieldsForSearch

func GetFieldsForSearch(searchArguments *client.SearchArguments) logrus.Fields

func Is256ColorSupported

func Is256ColorSupported() bool

func IsColorEnabled

func IsColorEnabled() bool

func IsTerminal

func IsTerminal(f *os.File) bool

func IsTrueColorSupported

func IsTrueColorSupported() bool

func ListSupportedFormats

func ListSupportedFormats(quote bool) (list []string)

func PrintlnAndExit

func PrintlnAndExit(format string, a ...any)

Print to Stdout and exit.

func SniffFormat

func SniffFormat(filename, format string) string

func Stderr

func Stderr() *os.File

func Stdin

func Stdin() *os.File

func Stdout

func Stdout() *os.File

func TerminalSize

func TerminalSize(f *os.File) (int, int, error)

Types

type Fields

type Fields = logrus.Fields

Jump to

Keyboard shortcuts

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