我是golang的新手,我正在使用代碼gangsta cli框架[https://github.com/codegangsta/cli]來開發命令行應用程序。我正試圖爲這些命令的標誌實現自動完成功能,但看起來它不像預期的那樣工作。有沒有人試圖使用這個框架來實現這個功能?bash自動完成使用codegangsta 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 = "[email protected]"
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閱讀鳴叫--a [TAB] [TAB]不起作用。
它適合你嗎?有什麼建議麼? – CodeQuestor 2017-01-04 10:42:17