Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix README.md links and add example #9

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
# 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

### 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)
}
```
Loading