Documentation ¶
Overview ¶
Package flagfile allows to define program flags that fill other flags from files.
See github.com/dolmen-go/flagx/flagfile/flagjson as an implementation using JSON files.
Example ¶
package main import ( "flag" "fmt" "github.com/dolmen-go/flagx/flagfile" ) func main() { flags := flag.NewFlagSet("test", flag.PanicOnError) // Usually flag.CommandLine flags.Var(flagfile.File(flags, flagfile.Lines), "args", "args from file (one line = one argument)") b := flags.Bool("bool", false, "bool test") i := flags.Int("int", 0, "int test") s := flags.String("string", "", "string test") flags.Parse([]string{ "-args", "testdata/args.txt", }) fmt.Println(*b, *i, *s) }
Output: true 1 foo
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func File ¶
File allows to define a command-line flag that gives a path to a structured file whose content will be expanded as command-line arguments and injected into flagset.
The structured data may be:
- an array of strings given to [flagset.Parse]
- a map where keys are argument names (without leading '-') and keys are values or arrays of values
This flag is reentrant, so the file may refer to (include) other files by reusing the same flag.
Types ¶
type FlagSet ¶
FlagSet is a subset of methods of *flag.FlagSet. flag.CommandLine is a well known global instance.
Click to show internal directories.
Click to hide internal directories.