caddycmd

package
v2.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: Apache-2.0 Imports: 30 Imported by: 149

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminAPIRequest added in v2.5.0

func AdminAPIRequest(adminAddr, method, uri string, headers http.Header, body io.Reader) (*http.Response, error)

AdminAPIRequest makes an API request according to the CLI flags given, with the given HTTP method and request URI. If body is non-nil, it will be assumed to be Content-Type application/json. The caller should close the response body. Should only be used by Caddy CLI commands which need to interact with a running instance of Caddy via the admin API.

func CaddyVersion added in v2.4.5

func CaddyVersion() string

CaddyVersion returns a detailed version string, if available.

func Commands added in v2.4.5

func Commands() map[string]Command

Commands returns a list of commands initialised by RegisterCommand

func DetermineAdminAPIAddress added in v2.5.0

func DetermineAdminAPIAddress(address, configFile, configAdapter string) (string, error)

DetermineAdminAPIAddress determines which admin API endpoint address should be used based on the inputs. By priority: if `address` is specified, then it is returned; if `configFile` (and `configAdapter`) are specified, then that config will be loaded to find the admin address; otherwise, the default admin listen address will be returned.

func LoadConfig added in v2.5.0

func LoadConfig(configFile, adapterName string) ([]byte, string, error)

LoadConfig loads the config from configFile and adapts it using adapterName. If adapterName is specified, configFile must be also. If no configFile is specified, it tries loading a default config file. The lack of a config file is not treated as an error, but false will be returned if there is no config available. It prints any warnings to stderr, and returns the resulting JSON config bytes along with the name of the loaded config file (if any).

func Main

func Main()

Main implements the main function of the caddy command. Call this if Caddy is to be the main() of 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

	// Func 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 float64 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