goargs

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 5 Imported by: 1

README

goargs

package main

import (
	"fmt"
	"os"

	"github.com/PKeidel/goargs"
)

func main() {
	var args struct {
		Host string `goargs:"long:host,short:h"`
		User string
	}

	goargs.Bind(&args)

	goargs.EnvPrefix = ""
    goargs.ParseWith(
		[]string{"test", "--host", "localhost"},
		os.Environ(),
	)

	fmt.Printf("Host: %s\n", args.Host)
	fmt.Printf("User: %s\n", args.User)

    fmt.Println("To rerun, run:", os.Args[0], goargs.String())
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultArgs        []*Arg
	ArgsByLongname     = make(map[string]*Arg, 0)
	DefaultSourceOrder = []SourceType{SourceFile, SourceEnv, SourceArgs}
	EnvPrefix          = "GOARG_"
)

Functions

func Bind

func Bind(obj interface{})

func Parse

func Parse()

Parse will parse the input sources (goargs.DefaultSourceOrder) only once, these values are set for the full program lifetime

func ParseWith

func ParseWith(args, envs []string)

func String

func String() string

Types

type Arg

type Arg struct {
	Source *SourceType

	Required bool
	// contains filtered or unexported fields
}

func WithIntS

func WithIntS(longName, shortName string, ref *int) *Arg

func WithString

func WithString(longName string, ref *string) *Arg

func WithStringS

func WithStringS(longName, shortName string, ref *string) *Arg

func (*Arg) String

func (a *Arg) String() string

type ArgType

type ArgType uint8
const (
	TypeString ArgType = iota
	TypeBool
	TypeInt
)

func (ArgType) String

func (i ArgType) String() string

type SourceType

type SourceType uint8
const (
	SourceNotFound SourceType = iota
	SourceFile
	SourceEnv
	SourceArgs
)

func (SourceType) String

func (i SourceType) String() string

Directories

Path Synopsis
cmd
generate command

Jump to

Keyboard shortcuts

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