flag

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

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

Source implements a CLI flag settings source. Note all keys are transformed using its KeyTransform method.

func New

func New(osArgs []string) (source *Source)

New creates a new flags source from OS arguments. WARNING: flags are not typed therefore DO NOT place a short boolean flag before a command word, for example do not use: ./program --enabled command You can however safely use: ./program --enabled=true command Boolean short flags without an equal sign or a value after have their value set to "true". All flag keys read are eventually transformed using the KeyTransform method.

func (*Source) Get

func (f *Source) Get(key string) (value string, isSet bool)

Get returns the value of the flag corresponding to the given key, and a boolean `isSet` to indicate if it is set or not.

func (*Source) KeyTransform

func (f *Source) KeyTransform(key string) (newKey string)

KeyTransform transforms a generic key to a flag key. It notably: - Changes all characters to be lowercase - Replaces all underscores and spaces with dashes.

func (*Source) String

func (f *Source) String() string

Jump to

Keyboard shortcuts

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