diff --git a/docs/v3/examples/arguments/advanced.md b/docs/v3/examples/arguments/advanced.md index 0d1dad3857..bfc96d4a8f 100644 --- a/docs/v3/examples/arguments/advanced.md +++ b/docs/v3/examples/arguments/advanced.md @@ -7,8 +7,8 @@ search: The [Basics] showed how to access arguments for a command. They are all retrieved as strings which is fine but it we need to say get integers or timestamps the user would have to convert from string to desired type. -To ease the burden on users the `cli` library offers predefined Arg and Args structure to faciliate this -The value of the argument can be retrieved using the command.Arg() function. For e.g +To ease the burden on users the `cli` library offers predefined `{Type}Arg` and `{Type}Args` structure to faciliate this +The value of the argument can be retrieved using the `command.{Type}Arg()` function. For e.g ```go package main import ( - "context" - "fmt" + "log" "os" + "context" - altsrc "github.com/urfave/cli-altsrc/v3" "github.com/urfave/cli/v3" + "github.com/urfave/cli-altsrc/v3" ) func main() { - flags := []cli.Flag{ - &cli.IntFlag{ - Name: "test", - Sources: altsrc.YAML("key", "/path/to/file"), - }, - &cli.StringFlag{Name: "load"}, - } - + var filename string cmd := &cli.Command{ - Action: func(context.Context, *cli.Command) error { - fmt.Println("--test value.*default: 0") - return nil + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "file", + Aliases: []string{"f"}, + Value: "/path/to/default", + Usage: "filename for mysql database", + Destination: &filename, + }, + &cli.StringFlag{ + Name: "password", + Aliases: []string{"p"}, + Usage: "password for the mysql database", + Sources: altsrc.YAML("somekey", altsrc.NewStringPtrSourcer(&filename)), + }, }, - Flags: flags, } - cmd.Run(context.Background(), os.Args) + if err := cmd.Run(context.Background(), os.Args); err != nil { + log.Fatal(err) + } } -``` \ No newline at end of file +```