cmd

package
v1.6.33 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 33 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main added in v1.6.14

func Main[T any](cmds T, description, version string) error

Main is the main entry point for all commands. It parses command-line arguments and then dispatches to the appropriate command handler.

func TerminalWidth added in v1.6.21

func TerminalWidth() int

TerminalWidth returns the width of os.Stdout if it is a terminal, or zero otherwise.

Types

type OpenAPICommand added in v1.6.19

type OpenAPICommand struct {
	JSON bool `name:"json" xor:"format" help:"Output OpenAPI spec as JSON."`
	YAML bool `name:"yaml" xor:"format" help:"Output OpenAPI spec as YAML."`
}

func (*OpenAPICommand) Run added in v1.6.19

func (cmd *OpenAPICommand) Run(ctx server.Cmd) error

type OpenAPICommands added in v1.6.19

type OpenAPICommands struct {
	OpenAPI OpenAPICommand `cmd:"" name:"openapi" help:"Show OpenAPI documentation in a browser, or output the spec as JSON or YAML." group:"SERVER"`
}

type RegisterFunc added in v1.6.14

type RegisterFunc func(*httprouter.Router) error

RegisterFunc is called after the server URL has been resolved but before the server starts serving requests. Use it to add routes and wire up handlers.

type RunServer added in v1.6.14

type RunServer struct {
	OpenAPI bool `name:"openapi" help:"Serve OpenAPI spec at {prefix}/openapi.{json,yaml,html}" default:"true" negatable:""`

	// TLS server options
	TLS struct {
		ServerName string `name:"name" help:"TLS server name"`
		CertFile   string `name:"cert" help:"TLS certificate file"`
		KeyFile    string `name:"key" help:"TLS key file"`
	} `embed:"" prefix:"tls."`

	// HTTP server options
	HTTP struct {
		Origin string `` /* 202-byte string literal not displayed */
	} `embed:"" prefix:"http."`
	// contains filtered or unexported fields
}

RunServer is a general-purpose "run" command. Embed it in your CLI's command struct to get a fully functional HTTP server with logging and OTel middleware.

func (*RunServer) Register added in v1.6.14

func (s *RunServer) Register(fns ...RegisterFunc) *RunServer

Register appends fns to the list of functions called to wire up routes before the server starts. Returns the receiver for chaining.

func (*RunServer) Run added in v1.6.14

func (s *RunServer) Run(ctx server.Cmd) error

Jump to

Keyboard shortcuts

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