From bcf109d0ab9c1302df75e0155e7c4ef07ddb5041 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 27 Jun 2024 09:02:09 +0300 Subject: [PATCH 1/2] Fix README.md links --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8552700..2ca1555 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# Welcome to urfave/cli-altsrc/v3 +# Welcome to `urfave/cli-altsrc/v3` [![Run Tests](https://github.com/urfave/cli-altsrc/actions/workflows/main.yml/badge.svg)](https://github.com/urfave/cli-altsrc/actions/workflows/main.yml) [![Go Reference](https://pkg.go.dev/badge/github.com/urfave/cli-altsrc/v3.svg)](https://pkg.go.dev/github.com/urfave/cli-altsrc/v3) [![Go Report Card](https://goreportcard.com/badge/github.com/urfave/cli-altsrc/v3)](https://goreportcard.com/report/github.com/urfave/cli-altsrc/v3) -urfave/cli-altsrc/v3 is an extended value source integration library for [urfave/cli/v3] with support for JSON, +[`urfave/cli-altsrc/v3`](https://pkg.go.dev/github.com/urfave/cli-altsrc/v3) is an extended value source integration library for [`urfave/cli/v3`] with support for JSON, YAML, and TOML. The primary reason for this to be a separate library is that third-party libraries are used for these -features which are otherwise not used throughout [urfave/cli/v3]. +features which are otherwise not used throughout [`urfave/cli/v3`]. -[urfave/cli/v3]: github.com/urfave/cli +[`urfave/cli/v3`]: https://github.com/urfave/cli From 0da9aa6c1a40ef45704b61d5e841c9987f1e66fb Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 27 Jun 2024 09:21:10 +0300 Subject: [PATCH 2/2] And add example --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 2ca1555..9a8dcb4 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,45 @@ YAML, and TOML. The primary reason for this to be a separate library is that thi features which are otherwise not used throughout [`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: 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) +} +```