Documentation ¶
Overview ¶
Package features enables a way to encode enabled features in a flag.FlagSet.
Example ¶
var ( testFeature = Feature("test-feature") // Set of flags which require a specific feature to be enabled. dependencies = []Dependency{ {Flag: "protected", Feature: testFeature}, } ) fs := flag.NewFlagSet("feature-flags", flag.PanicOnError) fs.String("protected", "", `Requires "test-feature" to be enabled to set.`) Register(fs, []Feature{testFeature}) if err := fs.Parse([]string{"--protected", "foo"}); err != nil { fmt.Println(err) } err := Validate(fs, dependencies) if err != nil { fmt.Println(err) } else { fmt.Println("Everything is valid!") }
Output: flag "protected" requires feature "test-feature" to be provided in --enable-features
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Enabled ¶
Enabled returns true if a feature is enabled. Enable will panic if fs has not been passed to Register or name is an unknown feature.
func GetAllEnabled ¶ added in v0.25.0
GetAllEnabled returns the list of all enabled features
Types ¶
type Dependency ¶
type Dependency struct { // Flag must be a flag name from a FlagSet. Flag string // Feature which must be enabled for Flag to be provided at the command line. Feature Feature }
Dependency marks a Flag as depending on a specific feature being enabled.
Click to show internal directories.
Click to hide internal directories.