registry

package
v0.0.0-...-052fa94 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

Package cloudeng.io/cmdutil/registry

import cloudeng.io/cmdutil/registry

Package registry provides support for various forms of registry useful for building command line tools.

Variables

ErrUnknownKey
ErrUnknownKey = errors.New("unregistered key")

ErrUnknownKey is returned when an unregistered key is encountered.

Functions

Func ConvertAnyArgs
func ConvertAnyArgs[T any](args ...any) []T

ConvertAnyArgs converts a variadic list of any to a slice of the specified type T, ignoring any arguments that are not of type T.

Func Scheme
func Scheme(path string) string

Scheme extracts the scheme from the given path, returning "file" if no scheme is present.

Types

Type New
type New[T any] func(ctx context.Context, args ...any) (T, error)

New is a function that creates a new instance of type T

Type T
type T[T any] struct {
	// contains filtered or unexported fields
}

T represents a registry for a specific type T that selected using a string key, which is typically a URI scheme.

Methods
func (r *T[RT]) Clone() *T[RT]

Clone creates a shallow clone of the registry.

func (r *T[T]) Get(key string) New[T]

Get retrieves the factory function for the given key, or nil if the key is not registered.

func (r *T[T]) Keys() []string

Keys returns a sorted list of all registered keys.

func (r *T[T]) Register(key string, factory New[T])

Register registers a new factory function for the given key.

Documentation

Overview

Package registry provides support for various forms of registry useful for building command line tools.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownKey = errors.New("unregistered key")

ErrUnknownKey is returned when an unregistered key is encountered.

Functions

func ConvertAnyArgs

func ConvertAnyArgs[T any](args ...any) []T

ConvertAnyArgs converts a variadic list of any to a slice of the specified type T, ignoring any arguments that are not of type T.

func Scheme

func Scheme(path string) string

Scheme extracts the scheme from the given path, returning "file" if no scheme is present.

Types

type New

type New[T any] func(ctx context.Context, args ...any) (T, error)

New is a function that creates a new instance of type T

type T

type T[T any] struct {
	// contains filtered or unexported fields
}

T represents a registry for a specific type T that selected using a string key, which is typically a URI scheme.

func (*T[RT]) Clone

func (r *T[RT]) Clone() *T[RT]

Clone creates a shallow clone of the registry.

func (*T[T]) Get

func (r *T[T]) Get(key string) New[T]

Get retrieves the factory function for the given key, or nil if the key is not registered.

func (*T[T]) Keys

func (r *T[T]) Keys() []string

Keys returns a sorted list of all registered keys.

func (*T[T]) Register

func (r *T[T]) Register(key string, factory New[T])

Register registers a new factory function for the given key.

Jump to

Keyboard shortcuts

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