此代码来自cliGo 包:https : //github.com/codegangsta/cli
package main
import (
"github.com/codegangsta/cli"
"os"
)
func main() {
app := cli.NewApp()
app.Name = "greet"
app.Usage = "fight the loneliness!"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "lang, l",
Value: "english",
Usage: "language for the greeting",
},
}
app.Action = func(c *cli.Context) {
name := "someone"
if len(c.Args()) > 0 {
name = c.Args()[0]
}
if c.String("lang") == "spanish" {
println("Hola", name)
} else {
println("Hello", name)
}
}
app.Run(os.Args)
}
我是 Go 初学者,我理解一切,除了这部分:
if len(c.Args()) > 0 {
name = c.Args()[0]
}
那个块说的是什么?为什么有必要?
蝴蝶不菲
相关分类