我是golang的新手,我正在使用代码gangsta cli框架[https://github.com/codegangsta/cli]来开发命令行应用程序。我正在尝试为命令的标志实现自动完成功能,但看起来它没有按预期工作。有没有人试图使用这个框架实现这个功能?
以下是我的代码部分:
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
)
func main() {
app := cli.NewApp()
app.Name = "greet"
app.Usage = "sample command-line app by greet"
app.Author = "abc"
app.Email = "xyz@aaa.com"
app.EnableBashCompletion = true
app.Commands = []cli.Command{
{
Name: "read",
ShortName: "r",
Usage: "read something",
Subcommands: []cli.Command{
{
Name: "articles",
Usage: "read articles",
Action: readArticles,
},
{
Name: "tweets",
Usage: "read Tweets",
Flags: []cli.Flag{
cli.StringFlag{
Name: "account",
Value: "SomeThing",
Usage: "name of Twitter account",
},
},
Action: readTwitter,
},
},
},
}
app.Run(os.Args)
}
func readArticles(ctx *cli.Context) {
fmt.Println("Go to http://www.google.com to read articles!")
}
func readTwitter(ctx *cli.Context) {
fmt.Printf("Go to https://twitter.com/%s to read tweets!", ctx.String("account"))
}
这是预期的输出:
./ greet read tweets --a [TAB] [TAB]不起作用。