为什么以下导入无效?

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

v2 of the package has no NewApp() method.

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.