summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-06-12 17:59:38 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-06-16 06:22:11 +0900
commit29de1da7c796051549f92a4a5ce1fae472ca3c7f (patch)
tree7127841bce71d50ae1e53fea932b2a10eb9723a2
parentbf2244229ce415c011c6e297bb7f1e3f9dd6b66b (diff)
cli: add a flag to generate bash completion file
generate bash completion file by $ gobgp -c We have to work more to generate more useful completion file automatically. Currently generated completion file can't complement dynamic commands e.g. gobgp neighbor <peer ip addr> local -a ipv6 <peer ip addr> is a dynamic command. Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--gobgp/main.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/gobgp/main.go b/gobgp/main.go
index 2e79b4bb..ba6c8d5f 100644
--- a/gobgp/main.go
+++ b/gobgp/main.go
@@ -21,11 +21,13 @@ import (
)
var globalOpts struct {
- Host string `short:"u" long:"url" description:"specifying an url" default:"127.0.0.1"`
- Port int `short:"p" long:"port" description:"specifying a port" default:"8080"`
- Debug bool `short:"d" long:"debug" description:"use debug"`
- Quiet bool `short:"q" long:"quiet" description:"use quiet"`
- Json bool `short:"j" long:"json" description:"use json format to output format"`
+ Host string `short:"u" long:"url" description:"specifying an url" default:"127.0.0.1"`
+ Port int `short:"p" long:"port" description:"specifying a port" default:"8080"`
+ Debug bool `short:"d" long:"debug" description:"use debug"`
+ Quiet bool `short:"q" long:"quiet" description:"use quiet"`
+ Json bool `short:"j" long:"json" description:"use json format to output format"`
+ GenCmpl bool `short:"c" long:"genbashcmpl" description:"use json format to output format"`
+ BashCmplFile string
}
var cmds []string
@@ -35,8 +37,13 @@ func main() {
rootCmd := &cobra.Command{
Use: "gobgp",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
- conn := connGrpc()
- client = api.NewGrpcClient(conn)
+ if !globalOpts.GenCmpl {
+ conn := connGrpc()
+ client = api.NewGrpcClient(conn)
+ }
+ },
+ Run: func(cmd *cobra.Command, args []string) {
+ cmd.GenBashCompletionFile(globalOpts.BashCmplFile)
},
}
@@ -45,6 +52,8 @@ func main() {
rootCmd.PersistentFlags().BoolVarP(&globalOpts.Json, "json", "j", false, "use json format to output format")
rootCmd.PersistentFlags().BoolVarP(&globalOpts.Debug, "debug", "d", false, "use debug")
rootCmd.PersistentFlags().BoolVarP(&globalOpts.Quiet, "quiet", "q", false, "use quiet")
+ rootCmd.PersistentFlags().BoolVarP(&globalOpts.GenCmpl, "gen-cmpl", "c", false, "generate completion file")
+ rootCmd.PersistentFlags().StringVarP(&globalOpts.BashCmplFile, "bash-cmpl-file", "", "gobgp_completion.bash", "bash cmpl filename")
globalCmd := NewGlobalCmd()
neighborCmd := NewNeighborCmd()