flag

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Flag Source

The flag source reads config from flags

Format

We expect the use of the flag package. Upper case flags will be lower cased. Dashes will be used as delimiters.

Example
dbAddress := flag.String("database-address", "127.0.0.1", "the db address")
dbPort := flag.Int("database-port", 3306, "the db port)

Becomes

{
    "database": {
        "address": "127.0.0.1",
        "port": 3306
    }
}

New Source

flagSource := flag.NewSource(
	// optionally enable reading of unset flags and their default
	// values into config, defaults to false
	IncludeUnset(true)
)

Load Source

Load the source into config

// Create new config
conf := config.NewConfig()

// Load flag source
conf.Load(flagSource)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IncludeUnset

func IncludeUnset(b bool) source.Option

IncludeUnset toggles the loading of unset flags and their respective default values. Default behavior is to ignore any unset flags.

func NewSource

func NewSource(opts ...source.Option) source.Source

NewSource returns a config source for integrating parsed flags. Hyphens are delimiters for nesting, and all keys are lowercased.

Example:

dbhost := flag.String("database-host", "localhost", "the db host name")

{
    "database": {
        "host": "localhost"
    }
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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