v2 => v3 migration guide #2084
Replies: 23 comments 11 replies
-
I found cli.App has gone. |
Beta Was this translation helpful? Give feedback.
-
App.EnableBashCompletion has gone. |
Beta Was this translation helpful? Give feedback.
-
App.Compiled has gone. |
Beta Was this translation helpful? Give feedback.
-
App.RunContext has gone. |
Beta Was this translation helpful? Give feedback.
-
The signature of ActionFunc was changed. v2 https://pkg.go.dev/github.com/urfave/cli/v2#ActionFunc type ActionFunc func(*Context) error v3 https://pkg.go.dev/github.com/urfave/cli/v3#ActionFunc type ActionFunc func(context.Context, *Command) error Methods such as Context.String were moved to Command. ctx.String() => cmd.String() |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
cli.NewApp has gone. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
cli.Author is gone |
Beta Was this translation helpful? Give feedback.
-
My change list: We are refactoring to urfave cli v3 from v2. Changes:
|
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
What is the replacement for |
Beta Was this translation helpful? Give feedback.
-
Before: &cli.TimestampFlag{
Name: "foo",
Layout: time.RFC3339,
} After: &cli.TimestampFlag{
Name: "foo",
Config: cli.TimestampConfig{
Layouts: []string{time.RFC3339},
},
} |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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
|
Beta Was this translation helpful? Give feedback.
-
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
} |
Beta Was this translation helpful? Give feedback.
-
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)
}
} |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Also looks like the |
Beta Was this translation helpful? Give feedback.
-
And generic flags now require a |
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
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
Beta Was this translation helpful? Give feedback.
All reactions