英文:
Why isn't the following import working?
问题
为什么以下代码可以正常工作:
package main
import (
"os"
cli "github.com/urfave/cli"
)
func main() {
cli.NewApp().Run(os.Args)
}
但是当我按照 https://github.com/urfave/cli 的建议将 cli
的导入更改为以下内容时:
import (
"os"
cli "gopkg.in/urfave/cli.v2"
)
就会出现错误 undefined: cli.NewApp
。
英文:
Why the following works
package main
import (
"os"
cli "github.com/urfave/cli"
)
func main() {
cli.NewApp().Run(os.Args)
}
but when I change the cli
import to following as suggested in https://github.com/urfave/cli
import (
"os"
cli "gopkg.in/urfave/cli.v2"
)
It gives this error undefined: cli.NewApp
答案1
得分: 5
v2版本的包没有NewApp()方法。
英文:
v2 of the package has no NewApp() method.
答案2
得分: 1
由于它不使用默认值进行初始化,所以下面的示例与NewApp()方法不完全相同,但如果你想尝试一下包的v2版本,可以尝试类似这样的代码。
package main
import (
"os"
cli "gopkg.in/urfave/cli.v2"
)
func main() {
(&cli.App{}).Run(os.Args)
}
请确保阅读v2包中包含的README.md文件,因为它还包含更新的说明和示例。
英文:
As it doesn't initialize with defaults the example below is not exactly the same as the NewApp() method, but you can try something like this, if you want to give v2 of the package a try.
package main
import (
"os"
cli "gopkg.in/urfave/cli.v2"
)
func main() {
(&cli.App{}).Run(os.Args)
}
Make sure to read the README.md file contained in the v2 package, as it also contains updated instructions and examples.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论