mains

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: ISC Imports: 20 Imported by: 2

Documentation

Overview

Package mains contains functions for executing a command-line utility

Index

Constants

View Source
const (
	// NoArguments besides switches, zero trailing arguments is allowed
	NoArguments = 1 << iota
	// OneArgument besides switches, exactly one trailing arguments is allowed
	OneArgument
	// ManyArguments besides switches, one or more trailing arguments is allowed
	ManyArguments
)
View Source
const (
	SilentString = "-" + silentOption
)

Variables

This section is empty.

Functions

func Abs

func Abs(dir string) (out string)

Abs ensures a file system path is fully qualified

func ExecDir

func ExecDir() (dir string)

ExecDir gets directory where executable is located

func FindFile

func FindFile(filename0, program string) (out string, bytes []byte)

FindFile locates and read the yaml file

func GetStringSliceValue

func GetStringSliceValue(p *[]string, value []string) (v flag.Value)

GetStringSliceValue initializes

func GetTopLevelKey

func GetTopLevelKey(topKey string) (key string)

GetTopLevelKey gets the top level key to use

func Keystrokes

func Keystrokes(ctx ev.Callee)

Keystrokes emits keystroke events

func ParentDir

func ParentDir() (dir string)

ParentDir gets absolute path of executable parent directory

func Timer

func Timer(ctx ev.Callee)

Timer displays a second counter and help on long-running invocations

func UserHomeDir

func UserHomeDir() (dir string)

UserHomeDir gets file system path of user’s home directory

Types

type ArgumentSpec

type ArgumentSpec uint32

ArgumentSpec bitfield for 0, 1, many arguments following command-line switches

type BaseOptionsType

type BaseOptionsType = struct {
	YamlFile  string
	YamlKey   string
	Verbosity string
	Debug     bool
	Silent    bool
}
var BaseOptions BaseOptionsType

type Executable

type Executable struct {
	Program        string // gonet
	Version        string // 0.0.1
	Comment        string // [ banner text after program and version] options parsing (about this version)
	Description    string // [Description part of usage] configures firewall and routing
	Copyright      string // © 2020…
	License        string // ISC License
	ArgumentsUsage string
	Arguments      ArgumentSpec // eg. NoArguments
	// fields below popualted by .Init()
	Launch       time.Time
	LaunchString string
	Host         string // short hostname, ie. no dots

	ArgCount        int
	Arg             string
	Args            []string
	IsLongErrors    bool
	IsErrorLocation bool
	// contains filtered or unexported fields
}

Executable constant strings that describes an executable

func (*Executable) AddErr

func (ex *Executable) AddErr(err error) (x *Executable)

AddErr extended with immediate printing of first error

func (*Executable) ApplyYaml

func (ex *Executable) ApplyYaml(yamlFile, yamlKey string, thunk UnmarshalThunk, om []OptionData)

func (*Executable) ConfigureLog

func (ex *Executable) ConfigureLog() (ex1 *Executable)

func (*Executable) Exit

func (ex *Executable) Exit()

Exit terminate from mains.err: exit 0 or echo to stderr and status code 1

func (*Executable) Init

func (ex *Executable) Init() *Executable

Init populate launch time — may throw

func (*Executable) LongErrors

func (ex *Executable) LongErrors(isLongErrors bool, isErrorLocation bool) *Executable

LongErrors sets if errors are printed with stack trace and values

func (*Executable) PrintBannerAndParseOptions

func (ex *Executable) PrintBannerAndParseOptions(om []OptionData) (ex1 *Executable)

PrintBannerAndParseOptions prints greeting

func (*Executable) PrintErr

func (ex *Executable) PrintErr(err error)

PrintErr prints an error

func (*Executable) Recover

func (ex *Executable) Recover()

Recover function to be deferred in main()

type InputLine

type InputLine string

type OptionData

type OptionData struct {
	P     interface{}
	Name  string
	Value interface{}
	Usage string
	Y     *YamlValue // pointer to data value from yaml
}

OptionData contain options data for the flag package

func BaseOptionData

func BaseOptionData(program string, yaml YamlOption) (od []OptionData)

func (*OptionData) AddOption

func (om *OptionData) AddOption()

AddOption executes flag.BoolVar and such on the options map

func (*OptionData) ApplyYaml

func (om *OptionData) ApplyYaml() (err error)

type Status

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

Status handles printing of status to stdout

func GetStatus

func GetStatus() (stat *Status)

GetStatus gets instance of status printer

func (*Status) Clear

func (stat *Status) Clear()

Clear remove previously printed status

func (*Status) Print

func (stat *Status) Print(s string)

Print status information

type StringSliceValue

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

StringSliceValue manages a string-slice value for flag.Var

func (*StringSliceValue) Set

func (v *StringSliceValue) Set(s string) (err error)

Set updates the string slice

func (StringSliceValue) String

func (v StringSliceValue) String() (s string)

type UnmarshalFunc

type UnmarshalFunc func(in []byte, out interface{}) (err error) // yaml.Unmarshal

type UnmarshalThunk

type UnmarshalThunk func(bytes []byte, unmarshal UnmarshalFunc, yamlKey string) (hasDate bool, err error)

type YamlOption

type YamlOption bool
const (
	YamlNo  YamlOption = false
	YamlYes YamlOption = true
)

type YamlValue

type YamlValue struct {
	Name    string
	Pointer interface{}
}

func NewYamlValue

func NewYamlValue(instancePointer interface{}, fieldPointer interface{}) (yv *YamlValue)

Jump to

Keyboard shortcuts

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