Documentation ¶
Overview ¶
Package cli contains utilities for command line tools and server main()s to handle flags, arguments, version, logging (fortio.org/log), etc... Configure using the package variables (at minimum MinArgs unless your binary only accepts flags), setup additional flag before calling Main or fortio.org/scli.ServerMain for configmap and dynamic flags setup. Also supports (sub)commands style, see CommandBeforeFlags and Command.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Out parameters: // *Version 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 Command string // first argument, if [CommandBeforeFlags] is true. // Following can/should be specified. ProgramName string // Used at the beginning of Usage() // Optional for programs using subcommand, command will be set in [Command]. CommandBeforeFlags bool // 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, not counting (optional) command. MaxArgs int // Maximum number of arguments expected. 0 means same as MinArgs. -1 means no limit. // 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 )
Configuration for your Main() or ServerMain() function. These variables is how to setup the arguments, flags and usage parsing for Main and [ServerMain]. At minium set the MinArgs should be set.
Functions ¶
func ErrUsage ¶
Show usage and error message on stderr and calls ExitFunction with code 1.
func Main ¶
func Main()
Main handles your commandline and flag parsing. Sets up flags first then call Main. For a server with dynamic flags, call ServerMain instead. Will either have called ExitFunction (defaults to os.Exit) or returned if all validations passed.
Types ¶
This section is empty.