cli

package
v5.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	FlagTypeNone   = iota
	FlagTypeString = iota
	FlagTypeInt    = iota
)
View Source
const ComponentName = "cli"

Variables

View Source
var Plugins = generic.NewContainer(func(opts ...Option) Cli { return nil })

Functions

func PrefixEnv

func PrefixEnv(prefix, name string) string

func PrefixName

func PrefixName(prefix, name string) string

func ProvideConfig

func ProvideConfig(
	_ di.DiFlags,
	diFlags *DiParsed,
	cfg *Config,
) (di.DiConfig, error)

Types

type Cli

type Cli interface {
	// Add adds a Flag to CLI
	Add(opts ...FlagOption) error

	// Parse parses flags from args you MUST Add Flags first
	Parse(args []string, opts ...Option) error

	// String returns the name of the current implementation
	String() string
}

func ProvideCli

func ProvideCli(
	config *Config,
) (Cli, error)

type CliConfig

type CliConfig struct {
	Name        string `json:"name" yaml:"Name"`
	Version     string `json:"version" yaml:"Version"`
	Description string `json:"description" yaml:"Description"`
	Usage       string `json:"usage" yaml:"Usage"`
	NoFlags     bool   `json:"no_flags" yaml:"NoFlags"`
	ArgPrefix   string `json:"arg_prefix" yaml:"ArgPrefix"`
	Plugin      string `json:"plugin" yaml:"Plugin"`
	ConfigFile  string `json:"config_file" yaml:"ConfigFile"`
	Flags       []Flag `json:"-" yaml:"-"`
}

type Config

type Config struct {
	Cli CliConfig `json:"cli" yaml:"Cli"`
}

func NewConfig

func NewConfig() *Config

func (*Config) Merge

func (d *Config) Merge(src *Config) error

type DiParsed

type DiParsed struct {
	ConfigFile string
}

func ProvideParsed

func ProvideParsed(
	config *Config,
	c Cli,
) (*DiParsed, error)

type Flag

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

	FlagType int

	DefaultString     string
	DestinationString *string

	DefaultInt     int
	DestinationInt *int
}

func NewFlag

func NewFlag(opts ...FlagOption) (*Flag, error)

func (*Flag) AsOptions

func (f *Flag) AsOptions() []FlagOption

type FlagOption

type FlagOption func(*Flag)

func Default

func Default[T any](n T) FlagOption

func Destination

func Destination[T any](n T) FlagOption

func EnvVars

func EnvVars(n ...string) FlagOption

func Name

func Name(n string) FlagOption

func Usage

func Usage(n string) FlagOption

type Option

type Option func(*Options)

func CliDescription

func CliDescription(n string) Option

func CliName

func CliName(n string) Option

func CliUsage

func CliUsage(n string) Option

func CliVersion

func CliVersion(n string) Option

type Options

type Options struct {
	// Name is the name of the app
	Name string

	// Description is the description of the app
	Description string

	// Version is the Version of the app
	Version string

	// Usage is the apps usage string
	Usage string
}

func NewCLIOptions

func NewCLIOptions(opts ...Option) *Options

Jump to

Keyboard shortcuts

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