cli

package
v0.0.0-...-e60230f Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package cli is the Cli component of orb.

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")

	// Plugins contains source/cli subplugins, for example urfave, pflag, cobra.
	Plugins = container.NewMap[ParseFunc]() //nolint:gochecknoglobals
	// Flags is the global flag container where you have to register flags with.
	Flags = container.NewList[*Flag]() //nolint:gochecknoglobals
)

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() source.Source

New creates a new cli source.

Types

type Config

type Config struct {
	Name    string `json:"name" yaml:"name"`
	Version string `json:"version" yaml:"version"`
}

Config is the base config for this component.

func NewConfig

func NewConfig() *Config

NewConfig returns the cli config.

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 flag.

func (*Flag) String

func (f *Flag) String() string

type FlagOption

type FlagOption func(*Flag)

FlagOption is an option for NewFlag.

func CPSlice

func CPSlice(n []string) FlagOption

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

func ConfigPath

func ConfigPath(n string) FlagOption

ConfigPath sets the ConfigPath for the flag.

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(config *Config, flags []*Flag, args []string) error

ParseFunc is the subplugin of source/cli.

type Source

type Source struct{}

Source is the cli source.

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(u *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