Documentation ¶
Overview ¶
Package cli contains utilities for command line tools and server main()s to handle flags, arguments, version, logging (fortio.org/log), etc... And for ServerMain the setup of a confimap/directory watch for flags and a config endpoint (uses fortio.org/dflag). Configure Config (Configuration fields), setup additional [flag]s before calling Main or ServerMain.
Index ¶
- Variables
- func ErrArgCount(prefix string, expected, actual int) bool
- func ErrUsage(msg string, args ...any) bool
- func Main() bool
- func Plural(i int, noun string) string
- func PluralExt(i int, noun string, ext string) string
- func ServerMain() bool
- func Usage(w io.Writer, msg string, args ...any)
- type Configuration
Constants ¶
This section is empty.
Variables ¶
var ( // Config is how to setup the arguments, flags and usage parsing for [Main] and [ServerMain]. // At minium set the MinArgs and MaxArgs fields. See [Configuration] for the fields. Config Configuration QuietFlag = flag.Bool("quiet", false, "Quiet mode, sets log level to warning") // If not set to true, will setup static loglevel flag and logger output for client tools. ServerMode = false // Override this to change the exit function (for testing), will be applied to log.Fatalf too. ExitFunction = os.Exit )
Functions ¶
func ErrArgCount ¶ added in v0.3.0
func Main ¶
func Main() bool
Main handles your commandline and flag parsing. Sets up flags first then call Main. For a server with dynamic flags, call ServerMain instead. returns true if there was no error. Might not return and have already exited for help/usage/etc...
func PluralExt ¶ added in v0.3.0
PluralExt returns the noun with an extension if i is not 1. Eg: PluralExt(1, "address", "es") -> "address" PluralExt(3 /* or 0 */, "address", "es") -> "addresses"
func ServerMain ¶
func ServerMain() bool
ServerMain returns true if a config port server has been started caller needs to select {} after its own code is ready. Will have exited if there are usage errors (wrong number of arguments, bad flags etc...). It sets up (optional) config-dir to watch and listen on config-port for dynamic flag changes and UI/api.
Types ¶
type Configuration ¶ added in v0.2.0
type Configuration struct { // Will be filled automatically by the cli package, using fortio.org/version FromBuildInfo(). ShortVersion string // x.y.z from tag/install LongVersion string // version plus go version plus OS/arch FullVersion string // LongVersion plus build date and git sha // Following should be specified. ProgramName string // Used at the beginning of Usage() // Cli usage/arguments example, ie "url1..." program name and "[flags]" will be added" // can include \n for additional details in the Usage() before the flags are dumped. ArgsHelp string MinArgs int // Minimum number of arguments expected MaxArgs int // Maximum number of arguments expected. 0 means same as MinArgs. -1 means no limit. // contains filtered or unexported fields }
Configuration for your Main() or ServerMain() function.