caddycmd

package
v2.0.0-unotech Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main()

Main implements the main function of the caddy command. Call this if Caddy is to be the main() if your program.

func RegisterCommand

func RegisterCommand(cmd Command)

RegisterCommand registers the command cmd. cmd.Name must be unique and conform to the following format:

  • lowercase
  • alphanumeric and hyphen characters only
  • cannot start or end with a hyphen
  • hyphen cannot be adjacent to another hyphen

This function panics if the name is already registered, if the name does not meet the described format, or if any of the fields are missing from cmd.

This function should be used in init().

Types

type Command

type Command struct {
	// The name of the subcommand. Must conform to the
	// format described by the RegisterCommand() godoc.
	// Required.
	Name string

	// Run is a function that executes a subcommand using
	// the parsed flags. It returns an exit code and any
	// associated error.
	// Required.
	Func CommandFunc

	// Usage is a brief message describing the syntax of
	// the subcommand's flags and args. Use [] to indicate
	// optional parameters and <> to enclose literal values
	// intended to be replaced by the user. Do not prefix
	// the string with "caddy" or the name of the command
	// since these will be prepended for you; only include
	// the actual parameters for this command.
	Usage string

	// Short is a one-line message explaining what the
	// command does. Should not end with punctuation.
	// Required.
	Short string

	// Long is the full help text shown to the user.
	// Will be trimmed of whitespace on both ends before
	// being printed.
	Long string

	// Flags is the flagset for command.
	Flags *flag.FlagSet
}

Command represents a subcommand. Name, Func, and Short are required.

type CommandFunc

type CommandFunc func(Flags) (int, error)

CommandFunc is a command's function. It runs the command and returns the proper exit code along with any error that occurred.

type Flags

type Flags struct {
	*flag.FlagSet
}

Flags wraps a FlagSet so that typed values from flags can be easily retrieved.

func (Flags) Bool

func (f Flags) Bool(name string) bool

Bool returns the boolean representation of the flag given by name. It returns false if the flag is not a boolean type. It panics if the flag is not in the flag set.

func (Flags) Duration

func (f Flags) Duration(name string) time.Duration

Duration returns the duration representation of the flag given by name. It returns false if the flag is not a duration type. It panics if the flag is not in the flag set.

func (Flags) Float64

func (f Flags) Float64(name string) float64

Float64 returns the float64 representation of the flag given by name. It returns false if the flag is not a float63 type. It panics if the flag is not in the flag set.

func (Flags) Int

func (f Flags) Int(name string) int

Int returns the integer representation of the flag given by name. It returns 0 if the flag is not an integer type. It panics if the flag is not in the flag set.

func (Flags) String

func (f Flags) String(name string) string

String returns the string representation of the flag given by name. It panics if the flag is not in the flag set.

Directories

Path Synopsis
Package main is the entry point of the Caddy application.
Package main is the entry point of the Caddy application.

Jump to

Keyboard shortcuts

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