v2 => v3 migration guide #2084
Replies: 23 comments 11 replies
|
I found cli.App has gone. |
|
App.EnableBashCompletion has gone. |
|
App.Compiled has gone. |
|
App.RunContext has gone. |
|
The signature of ActionFunc was changed. v2 https://pkg.go.dev/github.com/urfave/cli/v2#ActionFunc type ActionFunc func(*Context) errorv3 https://pkg.go.dev/github.com/urfave/cli/v3#ActionFunc type ActionFunc func(context.Context, *Command) errorMethods such as Context.String were moved to Command. ctx.String() => cmd.String() |
This comment has been hidden.
This comment has been hidden.
|
cli.NewApp has gone. |
|
cli.Author is gone |
|
My change list: We are refactoring to urfave cli v3 from v2. Changes:
|
|
App.BashComplete has gone. https://pkg.go.dev/github.com/urfave/cli/v2#App Command.ShellComplete https://pkg.go.dev/github.com/urfave/cli/v3#Command |
|
What is the replacement for |
|
Before: &cli.TimestampFlag{
Name: "foo",
Layout: time.RFC3339,
}After: &cli.TimestampFlag{
Name: "foo",
Config: cli.TimestampConfig{
Layouts: []string{time.RFC3339},
},
} |
|
The |
|
cli.ShowVersion was changed. v2: https://pkg.go.dev/github.com/urfave/cli/v2#ShowVersion Lines 312 to 319 in 9d76d15 cCtx has the information of the root App. v3: https://pkg.go.dev/github.com/urfave/cli/v3#ShowVersion Lines 331 to 339 in c96fd24 On the other hand, when we implement |
|
The default shell completion flag was changed. v2: https://cli.urfave.org/v2/examples/bash-completions/#customization
v3: https://cli.urfave.org/v3/examples/completions/shell-completions/#customization
|
|
value of uintFlag == "v2" // cli.UintFlag from uint
func withGlobalFlag(c *cli.Command) error {
timeoutSecond := c.Uint("timeout_second")
return nil
}== "v3" // to uint64
func withGlobalFlag(c *cli.Command) error {
timeoutSecond := uint(c.Uint("timeout_second"))
return nil
} |
|
List of all authors who contribute == "v2" func main() {
app := cli.NewApp()
app.Name = "testcli"
app.Version = "1.0.0"
author := &cli.Author{
Name: jsonAuthor.Name,
Email: jsonAuthor.Email,
}
app.Authors = []*cli.Author{
author,
}
app.Action = func(c *cli.Context) error {
args := c.Args()
fmt.Println(args)
return nil
}
if err := app.Run(os.Args); err != nil {
fmt.Println(err)
}
}== "v3" 3.1.+ with func main() {
app := &cli.Command{
Name: "testcli",
Version: "1.0.0",
}
// some kit get Author struct by json raw.
jsonAuthor := pkg_kit.GetPackageJsonAuthor()
app.Authors = []any{
jsonAuthor,
}
if err := app.Run(context.Background(), os.Args); err != nil {
fmt.Println(err)
}
} |
|
The docs say v3 is still considered alpha https://cli.urfave.org/#using-alpha-level-v3-releases, but there's now a 3.2 release. Do the docs need to be updated? |
|
The signature of Also is the goal to someday get these into the actual migration guide, or are they being kept separate for some reason? As I'm happy to try doing a few PRs for some of this stuff if that's ok |
|
Also looks like the |
|
And generic flags now require a |
|
@G-Rath Lots of changes have happened in the last year wrt this package. If you want to raise any PRs against docs please go for it. I will be happy to review |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
About the migration of v2 to v3, please see the guide: https://cli.urfave.org/migrate-v2-to-v3/
If you find any issues or questions, please post a comment on this discussion or consider sending a PR to help improve this guide.
Changes
Warning
This doesn't cover changes covered in the guide.
ActionFunc
v2 https://pkg.go.dev/github.com/urfave/cli/v2#ActionFunc
v3 https://pkg.go.dev/github.com/urfave/cli/v3#ActionFunc
Migration Script
https://github.com/suzuki-shunsuke/migrate-urfave-cli-v3
Note
All reactions