diff --git a/docs/migrate-v2-to-v3.md b/docs/migrate-v2-to-v3.md index 1b023ffcfd..ad2c566d17 100644 --- a/docs/migrate-v2-to-v3.md +++ b/docs/migrate-v2-to-v3.md @@ -23,6 +23,112 @@ Check each file for this and make the change. Shell command to find them all: `fgrep -rl github.com/urfave/cli/v2 *` +## New Names + +### cli.App + +=== "v2" + + ```go + cli.App{ + // ... + } + ``` + +=== "v3" + + ```go + cli.Command{ + // ... + } + ``` + +### cli.App.EnableBashCompletion + +=== "v2" + + ```go + cli.App{ + EnableBashCompletion: true, + } + ``` + +=== "v3" + + ```go + cli.Command{ + EnableShellCompletion: true, + } + ``` + +### cli.App.CustomAppHelpTemplate + +=== "v2" + + ```go + cli.App{ + CustomAppHelpTemplate: "...", + } + ``` + +=== "v3" + + ```go + cli.Command{ + CustomRootCommandHelpTemplate: "...", + } + ``` + +### cli.App.RunContext + +=== "v2" + + ```go + (&cli.App{}).RunContext(context.Background(), os.Args) + ``` + +=== "v3" + + ```go + (&cli.Command{}).Run(context.Background(), os.Args) + ``` + +### cli.App.BashComplete + +=== "v2" + + ```go + cli.App{ + BashComplete: func(ctx *cli.Context) {}, + } + ``` + +=== "v3" + + ```go + cli.Command{ + ShellComplete: func(ctx context.Context, cmd *cli.Command) {}, + } + ``` + +### cli.Command.Subcommands + +=== "v2" + + ```go + cli.Command{ + Subcommands: []*cli.Command{}, + } + ``` + +=== "v3" + + ```go + cli.Command{ + Commands: []*cli.Command{}, + } + ``` + ## Sources ### FilePath @@ -295,21 +401,3 @@ Similar messages would be shown for other funcs. }, } ``` - -## BashCompletion/ShellCompletion - -=== "v2" - - ```go - &cli.App{ - EnableBashCompletion: true, - } - ``` - -=== "v3" - - ```go - &cli.Command{ - EnableShellCompletion: true, - } - ``` 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 +```