cli

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 5 Imported by: 0

README

cli

I consistently needed a simple output printer for my console projects that did not require a lot of setup. Since I couldn't find a library to fill this role, I just wrote this project quickly for myself.

Features include:

  • cross-platform colored output
  • automatic tty detection
  • leveled printing

This library is not meant to be a comprehensive logging library. If you need more out of your logging library, I recommend Logrus.

Usage

example.go
package main

import "github.com/gesquive/cli"

func main() {
	cli.SetPrintLevel(cli.LevelInfo)
	cli.Debug("debug")
	cli.Info("info")
	cli.Warn("warn")
	cli.Error("error")
}
debug
info
warn
error

License

This library is made available under an MIT-style license. See LICENSE.

Contributing

PRs are always welcome!

Documentation

Index

Constants

View Source
const (
	LevelDebug = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
)

Print levels go in order: Debug, Info, Warn, Error, Fatal

Variables

Blue creates a blue string

Green creates a green string

Red creates a red string

View Source
var SprintfBlue = color.New(color.FgHiBlue).SprintfFunc()

SprintfBlue creates a blue formatted string

View Source
var SprintfGreen = color.New(color.FgHiGreen).SprintfFunc()

SprintfGreen creates a green formatted string

View Source
var SprintfRed = color.New(color.FgHiRed).SprintfFunc()

SprintfRed creates a red formatted string

View Source
var SprintfYellow = color.New(color.FgHiYellow).SprintfFunc()

SprintfYellow creates a yellow formatted string

View Source
var Yellow = SprintfYellow

Yellow creates a yellow string

Functions

func Debug

func Debug(format string, a ...interface{})

Debug prints a formatted debug level message with a newline appended

func Debugf

func Debugf(format string, a ...interface{})

Debugf prints a formatted debug level message

func Debugln

func Debugln(a ...interface{})

Debugln prints a debug level message with a newline appended

func Error

func Error(format string, a ...interface{})

Error prints a formatted error level message with a newline appended

func Errorf

func Errorf(format string, a ...interface{})

Errorf prints a formatted error level message

func Errorln

func Errorln(a ...interface{})

Errorln prints an error level message with a newline appended

func Fatal

func Fatal(format string, a ...interface{})

Fatal prints a formatted fatal level message with a newline appended and calls os.Exit(1)

func Fatalf

func Fatalf(format string, a ...interface{})

Fatalf prints a formatted fatal level message and calls os.Exit(1)

func Fatalln

func Fatalln(a ...interface{})

Fatalln prints a fatal level message with a newline appended and calls os.Exit(1)

func Info

func Info(format string, a ...interface{})

Info prints a formatted info level message with a newline appended

func Infof

func Infof(format string, a ...interface{})

Infof prints a formatted info level message

func Infoln

func Infoln(a ...interface{})

Infoln prints an info level message with a newline appended

func SetColor

func SetColor(colorOn bool)

SetColor sets the color status. True for color, False for no color

func SetErrorWriter

func SetErrorWriter(w io.Writer)

SetErrorWriter allows you to set the output writer for error and fatal messages

func SetOutputWriter

func SetOutputWriter(w io.Writer)

SetOutputWriter allows you to set the output file for debug, info, and warn messges

func SetPrintLevel

func SetPrintLevel(level int)

SetPrintLevel allows you to set the level to print, by default LevelInfo is set

func Warn

func Warn(format string, a ...interface{})

Warn prints a formatted warning level message with a newline appended

func Warnf

func Warnf(format string, a ...interface{})

Warnf prints a formatted warning level message

func Warnln

func Warnln(a ...interface{})

Warnln prints a warning level message with a newline appended

Types

This section is empty.

Jump to

Keyboard shortcuts

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