abstract

package
v0.0.0-...-923e5ac Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: GPL-3.0 Imports: 15 Imported by: 30

Documentation

Index

Constants

View Source
const (
	// to debug or not to debug, that is the question
	DEBUG = false

	// this token stands for stdin
	STDIN_TOKEN = "-"

	// part file extension
	EXTENSION_PART = ".part"

	// global setting for FADVICE_DONTNEED before reading
	SET_FILE_ADVICE_DONTNEED = true

	// TODO add more colors and colours
	TERMINAL_COLOR_JUNK        = "\x1b["
	TERMINAL_COLOR_JUNK_LENGTH = "\x1b[xxxxx"
	TERMINAL_COLOR_CYAN        = "\x1b[36;1m"
	TERMINAL_COLOR_BLUE        = "\x1b[34;1m"
	TERMINAL_COLOR_GREEN       = "\x1b[32;1m"
	TERMINAL_COLOR_RESET       = "\x1b[0m"

	// FIXME unknown escape sequence: e
	TERMINAL_BACKGROUND_GREEN = "\\e[42mGreen"
)
View Source
const (

	// Aus dem Hintergrund müsste Rahn schießen, Rahn schießt - TOR, TOR, TOR, TOR!
	SUCCESS = 0

	// for historic reasons, say 1 is FAILED
	FAILED = 1

	// from a given list, at least one part failed. check stderr.
	PARTLY = 2

	// output is empty, so a new line was not printed.
	EMPTY_OUTPUT = 9

	// some of the output wasn't outputted because it was empty.
	PARTLY_EMPTY = 10

	// maximum success. used internally for if exitCode > SUCCESSFUL
	SUCCESSFUL = 10

	// this shouldn't happen. declare the program received an error, but doesn't
	// know how to handle it or even what it is.
	ERROR_UNSPECIFIED = 100

	// it finally happend
	ERROR_DISK_FULL = 101

	// access denied in resource
	ERROR_ACCESS_DENIED = 102

	// couldn't write to resource
	ERROR_WRITE_ACCESS_DENID = 103

	// no input given
	ERROR_NO_INPUT = 104

	// unknown (kill) signal
	ERROR_INVALID_SIGNAL = 105

	// error parsing input
	ERROR_PARSING = 106

	// invalid argument
	ERROR_INVALID_ARGUMENT = 107

	// couldn't get working directory
	ERROR_WORKING_DIRECTORY = 108

	// doesn't exist
	ERROR_FILE_NOT_FOUND = 109

	// file already exist. file will not be overriden
	ERROR_FILE_EXIST = 110

	// open error
	ERROR_OPENING_FILE = 111

	// reading error on io.Read
	ERROR_READING = 112

	// couldn't stat inode
	ERROR_STAT = 113

	// TODO remove
	ERROR_COMPAT = 199

	// an unknown or unhandled internal error occured.
	ERROR_INTERNAL = 200

	// access denied to internally used resource. config file for example.
	ERROR_INTERNAL_ACCESS_DENIED = 201

	// write access denied to internally used resource. config file for example.
	ERROR_INTERNAL_WRITE_ACCESS_DENIED = 202

	// unhandled error. naughty programmer!
	ERROR_UNHANDLED = 254

	// this error should'nt be used. please be more fine grained.
	ERROR_GENERIC = 255
)
View Source
const (
	// try not to open more then this amount of goroutines for one task
	GOROUTINE_LIMIT = 500
	// perform a runtime.GC() followed by runtime.Gosched() when hitting GOROUTINE_LIMIT
	GOROUTINE_LIMIT_GC = true
	// try not to open more then this amount of goroutines for resources (files!)
	// must be divideable by 5 without leftovers
	GOROUTINE_LIMIT_RESOURCE = 50
	// 1 of 5
	GOROUTINE_LIMIT_RESOURCE_1OF5 = GOROUTINE_LIMIT_RESOURCE / 5
	// 4 of 5
	GOROUTINE_LIMIT_RESOURCE_4OF5 = GOROUTINE_LIMIT_RESOURCE_1OF5 * 4

	// the smallest read for an io.Reader buffer
	READ_BUFFER_SMALL_SIZE = 512
	// the usual read size for an io.Reader buffer
	READ_BUFFER_SIZE = 4 * 1024
	// the maximum read size for an io.Reader buffer
	READ_BUFFER_MAXIMUM_SIZE = 32 * 1024
)

Variables

This section is empty.

Functions

func ExitOnError

func ExitOnError(e error, writer io.Writer, exitCode uint8, message string, extra ...interface{})

if e != nil, exit

func HandleSignals

func HandleSignals()

func PrintError

func PrintError(e error, writer io.Writer, message string, extra ...interface{}) bool

func PrintErrorWithError

func PrintErrorWithError(e error, writer io.Writer, message string, extra ...interface{}) bool

Types

type Flags

type Flags struct {
	HasVerbose, HasHelp, HasVersion bool
	// tells you the level of verbosiness the user wants
	FlagVerboseLevel uint
	Debug            bool
	// contains filtered or unexported fields
}

func (*Flags) AddGeneralOptions

func (flags *Flags) AddGeneralOptions()

func (*Flags) Parse

func (flags *Flags) Parse() <-chan *optarg.Option

func (*Flags) ParseFinally

func (flags *Flags) ParseFinally() (bool, bool, bool, uint)

func (*Flags) ParseOption

func (flags *Flags) ParseOption(option *optarg.Option) bool

func (*Flags) Usage

func (flags *Flags) Usage()

func (*Flags) Validate

func (flags *Flags) Validate()

type Input

type Input struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	VerboseLevel uint

	Verbose, Help, Version bool
}

func (*Input) InitCli

func (input *Input) InitCli()

type Message

type Message struct {
	Format string
	Values []interface{}
	E      error
}

type Output

type Output struct {
	sync.Mutex
	// contains filtered or unexported fields
}

write in a separate goroutine to output writers (stdout, stderr)

func (*Output) Append

func (output *Output) Append(format string, values ...interface{})

func (*Output) Done

func (output *Output) Done()

func (*Output) Initialise

func (output *Output) Initialise(out, e io.Writer)

func (*Output) LinesManual

func (output *Output) LinesManual() bool

func (*Output) NewSubBuffer

func (output *Output) NewSubBuffer(name string, key int) OutputInterface

TODO add a possibilty to asynchronously flushing the buffer to it's parent when done TODO add a copy function return a new subbuffer that is automatically flushed to the main buffer when done name can be printed, key can be used for keeping a sort order in output

func (*Output) OrderBySubBufferKeys

func (output *Output) OrderBySubBufferKeys() bool

func (*Output) OrderBySubBufferNames

func (output *Output) OrderBySubBufferNames() bool

func (*Output) PrintSubBufferNames

func (output *Output) PrintSubBufferNames() bool

func (*Output) Reset

func (output *Output) Reset()

func (*Output) SetSortKey

func (output *Output) SetSortKey(to int)

func (*Output) SetSortTransformator

func (output *Output) SetSortTransformator(to func(string) string)

func (*Output) SortKey

func (output *Output) SortKey() int

output is a reduced version of sorted output

func (*Output) SortReversed

func (output *Output) SortReversed() bool

func (*Output) ToggleLinesManual

func (output *Output) ToggleLinesManual()

func (*Output) ToggleOrderBySubBufferKeys

func (output *Output) ToggleOrderBySubBufferKeys()

func (*Output) ToggleOrderBySubBufferNames

func (output *Output) ToggleOrderBySubBufferNames()

func (*Output) TogglePrintSubBufferNames

func (output *Output) TogglePrintSubBufferNames()

func (*Output) ToggleSortReversed

func (output *Output) ToggleSortReversed()

func (*Output) Wait

func (output *Output) Wait()

func (*Output) Write

func (output *Output) Write(values []byte) (int, error)

write through

func (*Output) WriteE

func (output *Output) WriteE(e error) bool

func (*Output) WriteEMessage

func (output *Output) WriteEMessage(e error, format string, values ...interface{}) bool

func (*Output) WriteError

func (output *Output) WriteError(format string, values ...interface{})

func (*Output) WriteFormatted

func (output *Output) WriteFormatted(format string, values ...interface{})

func (*Output) WriteLine

func (output *Output) WriteLine(values ...interface{})

func (*Output) WritePerLine

func (output *Output) WritePerLine(values ...interface{})

func (*Output) WriteSorted

func (output *Output) WriteSorted(format, sortkey string, values ...interface{})

write unsorted

type OutputInterface

type OutputInterface interface {
	sync.Locker
	io.Writer

	Initialise(io, e io.Writer)

	WriteFormatted(format string, values ...interface{})
	WriteLine(values ...interface{})
	WritePerLine(values ...interface{})
	// buffer output if aplicable and sort it before outputting
	WriteSorted(format, sortkey string, values ...interface{})

	// used for sorted output, otherwise the same as Write
	Append(format string, values ...interface{})

	WriteE(e error) bool
	WriteEMessage(e error, format string, values ...interface{}) bool
	WriteError(format string, values ...interface{})

	// state you are done. close channels
	Done()

	// wait till everyting is written
	Wait()

	SortKey() int
	SetSortKey(to int)
	SetSortTransformator(to func(string) string)
	SortReversed() bool
	ToggleSortReversed()

	LinesManual() bool
	ToggleLinesManual()

	NewSubBuffer(name string, key int) OutputInterface
	PrintSubBufferNames() bool
	TogglePrintSubBufferNames()
	OrderBySubBufferNames() bool
	ToggleOrderBySubBufferNames()
	OrderBySubBufferKeys() bool
	ToggleOrderBySubBufferKeys()
	// contains filtered or unexported methods
}

func NewOutput

func NewOutput(out, e io.Writer) (output OutputInterface)

func NewSortedOutput

func NewSortedOutput(out, e io.Writer) (output OutputInterface)

func NewSortedTabbedOutput

func NewSortedTabbedOutput(out, e io.Writer) OutputInterface

func NewTabbedOutput

func NewTabbedOutput(out, e io.Writer) OutputInterface

type SortedOutput

type SortedOutput struct {
	Output
	// contains filtered or unexported fields
}

buffers the output, but not e, until Done(), sorts that and outputs it to the given output

func (*SortedOutput) Append

func (output *SortedOutput) Append(format string, values ...interface{})

append to the last sort key

func (*SortedOutput) Done

func (output *SortedOutput) Done()

func (*SortedOutput) Initialise

func (output *SortedOutput) Initialise(out, e io.Writer)

func (*SortedOutput) NewSubBuffer

func (output *SortedOutput) NewSubBuffer(name string, key int) OutputInterface

TODO add a copy function

func (*SortedOutput) SetSortKey

func (output *SortedOutput) SetSortKey(to int)

func (*SortedOutput) SetSortTransformator

func (output *SortedOutput) SetSortTransformator(to func(string) string)

func (*SortedOutput) SortKey

func (output *SortedOutput) SortKey() int

func (*SortedOutput) WriteFormatted

func (output *SortedOutput) WriteFormatted(format string, values ...interface{})

soft sort. tries to use the first value as stringkey

func (*SortedOutput) WriteSorted

func (output *SortedOutput) WriteSorted(format, sortkey string, values ...interface{})

type TerminalInfo

type TerminalInfo struct {
	// contains filtered or unexported fields
}

func NewTerminalInfo

func NewTerminalInfo() *TerminalInfo

func (*TerminalInfo) Width

func (terminal *TerminalInfo) Width() int

Jump to

Keyboard shortcuts

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