pflagvar

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: BSD-3-Clause Imports: 3 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFlagsInStruct

func RegisterFlagsInStruct(pfs *pflag.FlagSet, tag string, structWithFlags interface{}, valueDefaults map[string]interface{}, usageDefaults map[string]string) error

RegisterFlagsInStruct is the same flagvar.RegisterFlagsInStruct except that it operates on pflag.FlagSet.

Example
package main

import (
	"fmt"

	"github.com/spf13/pflag"
	"v.io/x/lib/cmd/pflagvar"
)

func main() {
	eg := struct {
		A int    `flag:"int-flag,-1,intVar flag"`
		B string `flag:"string-flag,'some,value,with,a,comma',stringVar flag"`
		O int
	}{
		O: 23,
	}
	flagSet := &pflag.FlagSet{}
	err := pflagvar.RegisterFlagsInStruct(flagSet, "flag", &eg, nil, nil)
	if err != nil {
		panic(err)
	}
	fmt.Println(eg.A)
	fmt.Println(eg.B)
	flagSet.Parse([]string{"--int-flag=42"})
	fmt.Println(eg.A)
	fmt.Println(eg.B)
}
Output:

-1
some,value,with,a,comma
42
some,value,with,a,comma

Types

This section is empty.

Jump to

Keyboard shortcuts

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