confflags

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: MIT Imports: 3 Imported by: 0

README

conf-reader-flags

Code Analysis Go Reference codecov GitHub tag (latest SemVer)

The conf reader for Command Line Flags.

go get github.com/sv-tools/conf-reader-flags

License

MIT licensed. See the bundled LICENSE file for more details.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(mapFlagKey map[string]string, prefix string, flagSet *pflag.FlagSet) conf.Reader

New creates the Env reader

`mapFlagKey` is a map of the names of the flag and the configuration keys
`prefix` is a default prefix that will be added to all configuration keys
Example
package main

import (
	"context"
	"fmt"

	flag "github.com/spf13/pflag"
	"github.com/sv-tools/conf"

	confflags "github.com/sv-tools/conf-reader-flags"
)

func main() {
	flag.IntP("foo", "f", 1, "testing flag")
	if err := flag.CommandLine.Parse([]string{"--foo=42"}); err != nil {
		panic(err)
	}

	c := conf.New().WithReaders(confflags.New(map[string]string{"foo": "foo"}, "", nil))
	if err := c.Load(context.Background()); err != nil {
		panic(err)
	}

	fmt.Println(c.GetInt("foo"))
}
Output:

42

Types

This section is empty.

Jump to

Keyboard shortcuts

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