command

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultRunner = func() *Runner {
	result, err := NewRunner()
	if err != nil {
		log.Printf("Failed to create default runner: %v\n", err)
	}
	return result
}()

DefaultRunner does not record Prometheus metrics

Functions

This section is empty.

Types

type Command

type Command func(args []string) error

Command is a function that can be executed.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is a directory of available commands

Example
r := NewRegistry("a registry")

r.Add("Z command", func(_ []string) error { return nil })
r.Add("A command", func(_ []string) error { return nil })
r.Add("M command", func(_ []string) error { return nil })

list := r.List()
fmt.Println(list)
fmt.Println(r)
Output:

[A command M command Z command]
Command registry a registry: A command, M command, Z command

func NewRegistry

func NewRegistry(name string) *Registry

NewRegistry creates a new Registry

func (*Registry) Add

func (r *Registry) Add(cmdName string, cmd Command)

Add registers a command in the Registry

func (*Registry) List

func (r *Registry) List() []string

List returns a list of all registered commands

func (*Registry) Name

func (r *Registry) Name() string

Name returns the name of the Registry

func (*Registry) Run

func (r *Registry) Run(cmdName string, args []string) error

Run executes a command by name

func (*Registry) String

func (r *Registry) String() string

String returns a string representation of the Registry

type Runner added in v0.0.13

type Runner struct {
	// contains filtered or unexported fields
}

func NewRunner added in v0.0.13

func NewRunner(options ...RunnerOption) (*Runner, error)

func (*Runner) Run added in v0.0.13

func (r *Runner) Run(subsystem string, cmdName string, cmd Command, args ...string) error

Run executes the Command with the given name and arguments, injecting observability calls as required by the Runner configuration

type RunnerOption added in v0.0.13

type RunnerOption func(*Runner) error

func WithPrometheusNamespace added in v0.0.13

func WithPrometheusNamespace(namespace string) RunnerOption

WithPrometheusNamespace sets the namespace for the prometheus metrics. Prometheus metrics will be exposed only if this is called.

Jump to

Keyboard shortcuts

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