Documentation ¶
Overview ¶
Package util provides utility functions for the application. Survey framework is used to implement the interactive prompts.
Index ¶
- Constants
- Variables
- func AskBool(cmd *cobra.Command, flagName string, args *[]string, opts ...survey.AskOpt) (bool, error)
- func AskCommand(cmd *cobra.Command, def *cobra.Command, opts ...survey.AskOpt) (*cobra.Command, error)
- func AskFilterString(cmd *cobra.Command, flagName string, filterString *string, ...)
- func AskID(cmd *cobra.Command, flagName string, id *string, ...)
- func AskLDAPDataInterchangeFormat(requests *ldif.LDIF, editor string) (bool, error)
- func AskMultiline(cmd *cobra.Command, flagName string, args *[]string, opts ...survey.AskOpt) (bool, error)
- func AskString(cmd *cobra.Command, flagName string, args *[]string, password bool, def string, ...) (bool, error)
- func AskStrings(cmd *cobra.Command, flagName string, options, def []string, args *[]string, ...) (bool, error)
- func Flush(results attributes.Maps, requests *ldif.LDIF, format string, out io.Writer) error
- func GetFieldsForBind(bindParameters *auth.BindParameters, dialOptions *auth.DialOptions) logrus.Fields
- func GetFieldsForSearch(searchArguments *client.SearchArguments) logrus.Fields
- func HelpAliases(msg *string)
- func Is256ColorSupported() bool
- func IsColorEnabled() bool
- func IsTerminal(f *os.File) bool
- func IsTrueColorSupported() bool
- func ListSupportedFormats(quote bool) (list []string)
- func PrintColors(fn func(string, ...any) string, format string, a ...any) string
- func PrintlnAndExit(code int, format string, a ...any)
- func SniffFormat(filename, format string) string
- func Stderr() *os.File
- func Stdin() *os.File
- func Stdout() *os.File
- func TerminalSize(f *os.File) (int, int, error)
- type Fields
Constants ¶
const ( CSV = "csv" // CSV format, "," being used as delimiter DEFAULT = "default" // Colorful YAML output LDIF = "ldif" // LDAP Data Interchange Format YAML = "yaml" // YAML )
Variables ¶
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)
AskBool to select a boolean value for given flag, default value may be provided.
func AskCommand ¶
func AskCommand(cmd *cobra.Command, def *cobra.Command, opts ...survey.AskOpt) (*cobra.Command, error)
AskCommand to select a command from given commands' children, default command may be provided.
func AskFilterString ¶
func AskFilterString(cmd *cobra.Command, flagName string, filterString *string, searchArguments *client.SearchArguments)
AskFilterString asks for a filter string (LDAP syntax according to RFC 4515)
func AskID ¶
func AskID(cmd *cobra.Command, flagName string, id *string, searchArguments *client.SearchArguments)
AskID asks for an ID (CN, DN, GUID, SAN, UPN, Name or DisplayName)
func AskLDAPDataInterchangeFormat ¶
AskLDAPDataInterchangeFormat to modify given LDAP Data Interchange Format (LDIF) requests
func AskMultiline ¶
func AskMultiline(cmd *cobra.Command, flagName string, args *[]string, opts ...survey.AskOpt) (bool, error)
AskMultiline to select one or many values from many for given flag, default values may be provided (each option is separated by a new line).
func AskString ¶
func AskString(cmd *cobra.Command, flagName string, args *[]string, password bool, def string, opts ...survey.AskOpt) (bool, error)
AskString to select a string value for given flag, default value may be provided. If default value is not provided, the default value of the flag will be used. Password mode (sensitive input mode) is supported
func AskStrings ¶
func AskStrings(cmd *cobra.Command, flagName string, options, def []string, args *[]string, opts ...survey.AskOpt) (bool, error)
AskStrings to select one or many values from many for given flag, default values may be provided. If just one default option is being provided, a selection of only one option is foreseen, otherwise multiple selection is possible.
func Flush ¶
Encode results into given format. Writer is supposed to be either stdout or a file. Per default, colorful YAML format takes precedences and is being emitted to stdout
func GetFieldsForBind ¶
func GetFieldsForBind(bindParameters *auth.BindParameters, dialOptions *auth.DialOptions) logrus.Fields
GetFieldsForBind produces log fields describing a bind request
func GetFieldsForSearch ¶
func GetFieldsForSearch(searchArguments *client.SearchArguments) logrus.Fields
GetFieldsForSearch produces log fields describing a search request
func HelpAliases ¶
func HelpAliases(msg *string)
func Is256ColorSupported ¶
func Is256ColorSupported() bool
Is256ColorSupported checks if current terminal supports ANSI 256-bit color codes. Env variables TERM and COLORTERM are considered
func IsColorEnabled ¶
func IsColorEnabled() bool
IsColorEnabled checks if current terminal supports ANSI color codes. Env variables CLICOLOR_FORCE, NO_COLOR and CLICOLOR are being considered
func IsTerminal ¶
IsTerminal checks if given file descriptor is a terminal or just a pipe
func IsTrueColorSupported ¶
func IsTrueColorSupported() bool
IsTrueColorSupported checks if current terminal supports ANSI 24-bit color codes. Env variables TERM and COLORTERM are evaluated
func ListSupportedFormats ¶
ListSupportedFormats returns a list of supported formats
func PrintColors ¶
PrintColors prints formatted string with colors if supported
func PrintlnAndExit ¶
PrintColors prints a string with colors and exits with provided code
func SniffFormat ¶
SniffFormat returns the format of a file from its extension