argument

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: BSD-2-Clause Imports: 10 Imported by: 7

README

Argument

This library helps to fill command line args and enviroment variable to struct.

var data struct {
	Username string `arg:"username" env:"USERNAME" default:"ben"`
	Password string `arg:"password" env:"PASSWORD"`
}
if err := argument.Parse(&data); err != nil {
	log.Fatalf("parse args failed: %v", err)
}
fmt.Printf("username %s, password %s\n", data.Username, data.Password)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultValues

func DefaultValues(data interface{}) (map[string]interface{}, error)

DefaultValues returns all default values of the given struct.

func Fill

func Fill(data interface{}, values map[string]interface{}) error

Fill the given map into the struct.

func Parse

func Parse(data interface{}) error

Parse combines all functionality. It parse env args, fills it the struct, print all arguments and validate required fields are set.

func ParseArgs

func ParseArgs(data interface{}, args []string) error

ParseArgs into the given struct.

func ParseEnv

func ParseEnv(data interface{}, environ []string) error

ParseEnv into the given struct.

func Print

func Print(data interface{}) error

Print all configured arguments. Set display:"hidden" to hide or display:"length" to only print the arguments length.

func ValidateRequired

func ValidateRequired(data interface{}) error

ValidateRequired fields are set and returns an error if not.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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