argument

package module
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: BSD-2-Clause Imports: 12 Imported by: 1

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(ctx context.Context, data interface{}) (map[string]interface{}, error)

DefaultValues returns all default values of the given struct.

func Fill

func Fill(ctx context.Context, data interface{}, values map[string]interface{}) error

Fill the given map into the struct.

func Parse

func Parse(ctx context.Context, 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 ParseAndPrint added in v2.3.0

func ParseAndPrint(ctx context.Context, data interface{}) error

func ParseArgs

func ParseArgs(ctx context.Context, data interface{}, args []string) error

ParseArgs into the given struct.

func ParseEnv

func ParseEnv(ctx context.Context, data interface{}, environ []string) error

ParseEnv into the given struct.

func Print

func Print(ctx context.Context, 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(ctx context.Context, 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