cli

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package cli provides the CLI config component of go-micro.

Package cli provides cli.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFlagExists is returned when the given element exists in the flag container.
	ErrFlagExists = errors.New("element exists already")
)
View Source
var (
	// Flags is the global flag container where you have to register flags with.
	Flags = container.NewList[*Flag]()
)

Functions

func FlagValue

func FlagValue[T any](f *Flag) (T, error)

FlagValue gets a value back from a Flag and enforces types.

func New

func New(parser ParseFunc) source.Source

New creates a new cli source.

func ParseFlags added in v0.2.0

func ParseFlags(result *source.Data, flags []*Flag)

ParseFlags takes the list of flags and parses them into a map[string]any contained inside the result.

func ProvideConfigData added in v0.2.0

func ProvideConfigData(serviceName types.ServiceName, cliParser ParseFunc) (types.ConfigData, error)

ProvideConfigData provides configData from cli, this requires for example urfave.Provide to be registered first.

Types

type Flag

type Flag struct {
	Name    string
	EnvVars []string
	Usage   string

	// The path in map(\[string\])+any
	ConfigPath []string

	Default any
	Value   any
}

Flag is a Cli Flag and maybe environment variable.

func NewFlag

func NewFlag[T any](
	name string,
	defaultValue T,
	opts ...FlagOption,
) *Flag

NewFlag creates a new CLI flag.

func (*Flag) Clear added in v0.2.0

func (f *Flag) Clear()

Clear clears the internal value.

func (*Flag) String

func (f *Flag) String() string

type FlagOption

type FlagOption func(*Flag)

FlagOption is an option for NewFlag.

func ConfigPath

func ConfigPath(n string) FlagOption

ConfigPath sets the ConfigPath for the flag.

func ConfigPathSlice

func ConfigPathSlice(n []string) FlagOption

ConfigPathSlice is the same as ConfigPath but it accepts a slice.

func Default

func Default[T any](n T) FlagOption

Default sets the flags default.

func EnvVars

func EnvVars(n ...string) FlagOption

EnvVars set's environment variables for the flag.

func Usage

func Usage(n string) FlagOption

Usage set's the usage string for the flag.

type ParseFunc

type ParseFunc func() source.Data

ParseFunc is the subplugin of source/cli.

type Source

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

Source cli reads flags and environment variables into a config struct.

func (*Source) PrependSections

func (s *Source) PrependSections() bool

PrependSections indicates whether this needs sections to be prepended, which is true in this case.

func (*Source) Read

func (s *Source) Read(_ *url.URL) source.Data

Read creates the subplugin for the given url, creates its config after and then executes it.

func (*Source) Schemes

func (s *Source) Schemes() []string

Schemes returns the supported schemes by this plugin.

func (*Source) String

func (s *Source) String() string

String returns the name of this plugin.

Jump to

Keyboard shortcuts

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