https://github.com/urfave/cli-altsrc
Read values for urfave/cli/v3 flags from config files
https://github.com/urfave/cli-altsrc
cli golang golang-cli golang-library json toml yaml
Last synced: about 1 month ago
JSON representation
Read values for urfave/cli/v3 flags from config files
- Host: GitHub
- URL: https://github.com/urfave/cli-altsrc
- Owner: urfave
- License: mit
- Created: 2022-11-08T18:00:42.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-05T00:31:53.000Z (about 1 month ago)
- Last Synced: 2025-04-05T01:24:52.160Z (about 1 month ago)
- Topics: cli, golang, golang-cli, golang-library, json, toml, yaml
- Language: Go
- Homepage: https://pkg.go.dev/github.com/urfave/cli-altsrc/v3
- Size: 204 KB
- Stars: 23
- Watchers: 16
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Welcome to `urfave/cli-altsrc/v3`
[](https://github.com/urfave/cli-altsrc/actions/workflows/main.yml)
[](https://pkg.go.dev/github.com/urfave/cli-altsrc/v3)
[](https://goreportcard.com/report/github.com/urfave/cli-altsrc/v3)[`urfave/cli-altsrc/v3`](https://pkg.go.dev/github.com/urfave/cli-altsrc/v3) is an extension for [`urfave/cli/v3`] to read
flag values from JSON, YAML, and TOML. The extension keeps third-party libraries for these features away from [`urfave/cli/v3`].[`urfave/cli/v3`]: https://github.com/urfave/cli
### Example
```go
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: yaml.YAML("greet.name", configFiles...),
},
&cli.IntFlag{
Name: "enthusiasm",
Aliases: []string{"!"},
Sources: yaml.YAML("greet.enthusiasm", configFiles...),
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
punct := ""
if cmd.Int("enthusiasm") > 9000 {
punct = "!"
}fmt.Fprintf(os.Stdout, "Hello, %[1]v%[2]v\n", cmd.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!
```