Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Err = errors.New("urfave/cli-altsrc error")
)
Functions ¶
func JSON ¶
JSON is a helper function that wraps the YAML helper function and loads via yaml.Unmarshal
Example ¶
configFiles := []string{ filepath.Join(testdataDir, "config.json"), filepath.Join(testdataDir, "alt-config.json"), } app := &cli.Command{ Name: "greet", Flags: []cli.Flag{ &cli.StringFlag{ Name: "name", Aliases: []string{"n"}, Sources: altsrc.JSON("greet.name", configFiles...), }, &cli.IntFlag{ Name: "enthusiasm", Aliases: []string{"!"}, Sources: altsrc.JSON("greet.enthusiasm", configFiles...), }, }, Action: func(cCtx *cli.Context) error { punct := "" if cCtx.Int("enthusiasm") > 9000 { punct = "!" } fmt.Fprintf(os.Stdout, "Hello, %[1]v%[2]v\n", cCtx.String("name"), punct) return nil }, } // Simulating os.Args os.Args = []string{"greet"} if err := app.Run(context.Background(), os.Args); err != nil { fmt.Fprintf(os.Stdout, "OH NO: %[1]v\n", err) }
Output: Hello, Berry!
func TOML ¶
TOML is a helper function to encapsulate a number of tomlValueSource together as a cli.ValueSourceChain
Example ¶
configFiles := []string{ filepath.Join(testdataDir, "config.toml"), filepath.Join(testdataDir, "alt-config.toml"), } app := &cli.Command{ Name: "greet", Flags: []cli.Flag{ &cli.StringFlag{ Name: "name", Aliases: []string{"n"}, Sources: altsrc.TOML("greet.name", configFiles...), }, &cli.IntFlag{ Name: "enthusiasm", Aliases: []string{"!"}, Sources: altsrc.TOML("greet.enthusiasm", configFiles...), }, }, Action: func(cCtx *cli.Context) error { punct := "" if cCtx.Int("enthusiasm") > 9000 { punct = "!" } fmt.Fprintf(os.Stdout, "Hello, %[1]v%[2]v\n", cCtx.String("name"), punct) return nil }, } // Simulating os.Args os.Args = []string{"greet"} if err := app.Run(context.Background(), os.Args); err != nil { fmt.Fprintf(os.Stdout, "OH NO: %[1]v\n", err) }
Output: Hello, Berry!
func YAML ¶
YAML is a helper function to encapsulate a number of yamlValueSource together as a cli.ValueSourceChain
Example ¶
configFiles := []string{ filepath.Join(testdataDir, "config.yaml"), filepath.Join(testdataDir, "alt-config.yaml"), } app := &cli.Command{ Name: "greet", Flags: []cli.Flag{ &cli.StringFlag{ Name: "name", Aliases: []string{"n"}, Sources: altsrc.YAML("greet.name", configFiles...), }, &cli.IntFlag{ Name: "enthusiasm", Aliases: []string{"!"}, Sources: altsrc.YAML("greet.enthusiasm", configFiles...), }, }, Action: func(cCtx *cli.Context) error { punct := "" if cCtx.Int("enthusiasm") > 9000 { punct = "!" } fmt.Fprintf(os.Stdout, "Hello, %[1]v%[2]v\n", cCtx.String("name"), punct) return nil }, } // Simulating os.Args os.Args = []string{"greet"} if err := app.Run(context.Background(), os.Args); err != nil { fmt.Fprintf(os.Stdout, "OH NO: %[1]v\n", err) }
Output: Hello, Berry!
Types ¶
This section is empty.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.