caddycmd

package
v2.8.4 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2024 License: Apache-2.0 Imports: 37 Imported by: 186

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 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 string, config []byte, 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 `config` is specified, then that config will be used for finding the admin address; 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().

func WrapCommandFuncForCobra added in v2.7.0

func WrapCommandFuncForCobra(f CommandFunc) func(cmd *cobra.Command, _ []string) error

WrapCommandFuncForCobra wraps a Caddy CommandFunc for use in a cobra command's RunE field.

Types

type Command

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

	// 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.
	// This is ignored if CobraFunc is set.
	Flags *flag.FlagSet

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

	// CobraFunc allows further configuration of the command
	// via cobra's APIs. If this is set, then Func and Flags
	// are ignored, with the assumption that they are set in
	// this function. A caddycmd.WrapCommandFuncForCobra helper
	// exists to simplify porting CommandFunc to Cobra's RunE.
	CobraFunc func(*cobra.Command)
}

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 {
	*pflag.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.

type StringSlice added in v2.6.0

type StringSlice []string

StringSlice is a flag.Value that enables repeated use of a string flag.

func (*StringSlice) Set added in v2.6.0

func (ss *StringSlice) Set(value string) error

func (StringSlice) String added in v2.6.0

func (ss StringSlice) String() string

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