cli

package
v0.0.0-...-eabd6fe Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyTransformError

type BodyTransformError interface {
	error
}

type CliHandler

type CliHandler interface {
	Register(handler Handler)
	Execute(ctx context.Context, cmdline string) (Message, error)
	DescendHandlers(ctx context.Context, resp *Response, req *Request)
}

func NewCliHandler

func NewCliHandler() CliHandler

NewCliHandler returns a new and empty CliHandler.

type EmptyCommandLineError

type EmptyCommandLineError interface {
	error
}

type Handler

type Handler struct {
	// Use is the one-line usage message.
	// Example:  add [-F flag-val | -D flag-val] argument-val
	Use string

	// Short
	Short string

	// Command is the fully qualified command string.  If this is a sub-command
	// then the fully qualified string is "parent:sub:command"
	Command string

	// HandlerFn is the function to invoke to handle the command.  When
	// HandlerFn is invoked the command string will be striped from 'args'
	HandlerFn func(ctx context.Context, resp *Response, req *Request)
}
type Header struct {
	Key   string
	Value string
}

Header is a single key/value header field where both the key and the value are strings in the spirit of RFC5322, although necessarily conformant.

type Headers

type Headers []Header

Headers is aliased so that methods can be implemented

func (*Headers) Append

func (h *Headers) Append(k, v string)

func (*Headers) Contains

func (h *Headers) Contains(k string) bool

Contains returns true if 'k' is a key in h

func (*Headers) Delete

func (h *Headers) Delete(k string)

Delete removes the first header with key 'k'

func (*Headers) DeleteAll

func (h *Headers) DeleteAll(k string)

DeleteAll removes all headers with key 'k'

func (*Headers) Get

func (h *Headers) Get(k string) string

Get returns the value of the first header with key 'k' or the zero value string, ("")

func (*Headers) GetAll

func (h *Headers) GetAll(k string) []string

GetAll returns a list of string for each header with key 'k'

func (*Headers) Keys

func (h *Headers) Keys() []string

Keys returns a list of unique keys contained in the Headers

func (*Headers) Set

func (h *Headers) Set(k, v string)

Set sets the first header with key = 'k' to 'v' or appends a new Header to the list.

type Message

type Message interface {
	Headers() []Header
	Body() string
}

Message is the returned result of passing a command string into the CliHandler's Execute() function.

type MultiLineCommandLineError

type MultiLineCommandLineError interface {
	error
}

type Request

type Request struct {
	Command    string
	Args       []string
	CmdHandler CliHandler
}

Request is the internal structure used to pass a command request down the handler stack. Each level in the stack may mutate the Request object.

type Response

type Response struct {
	Headers Headers
	Body    any
	Err     error
}

Response is the internal structure used to return results from a command. A Response may be modified by each nested command as it is returned up the stack.

type UnknownCommandError

type UnknownCommandError interface {
	error
}

Jump to

Keyboard shortcuts

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