Skip to content

Commit

Permalink
Merge pull request #9 from urfave/abitrolly-patch-1
Browse files Browse the repository at this point in the history
Fix README.md links and add example
  • Loading branch information
abitrolly committed Jun 28, 2024
2 parents f2d36b9 + 0da9aa6 commit d37d3ea
Showing 1 changed file with 46 additions and 4 deletions.
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)
}
```

0 comments on commit d37d3ea

Please sign in to comment.