From 40beabffc3c8ca721ec57c3d7fe06d2bb9f3d710 Mon Sep 17 00:00:00 2001 From: Naoto Hanaue Date: Thu, 18 Jun 2015 10:42:19 +0900 Subject: cli: update to auto-complete the IP address of the neighbor --- tools/completion/gobgp-completion.bash | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'tools/completion') diff --git a/tools/completion/gobgp-completion.bash b/tools/completion/gobgp-completion.bash index 68718cf7..1f88a3c5 100644 --- a/tools/completion/gobgp-completion.bash +++ b/tools/completion/gobgp-completion.bash @@ -1,5 +1,15 @@ #!/bin/bash +__gobgp_q() { + gobgp 2>/dev/null "$@" +} + +__gobgp_q_neighbor() { + neighbors=( $(__gobgp_q $url $port --quiet $q_type) ) + for n in ${neighbors[*]}; do + must_have_one_noun+=($n) + done +} __debug() { @@ -106,7 +116,12 @@ __handle_flag() commands=() fi fi - + if [ ${words[(c-1)]} == "-u" ]; then + url="-u ${words[(c)]}" + fi + if [ ${words[(c-1)]} == "-p" ]; then + port="-p ${words[(c)]}" + fi # skip the flag itself c=$((c+1)) @@ -233,6 +248,16 @@ _gobgp_neighbor() { last_command="gobgp_neighbor" commands=() + commands+=("local") + commands+=("adj-in") + commands+=("adj-out") + commands+=("reset") + commands+=("softreset") + commands+=("softresetin") + commands+=("softresetout") + commands+=("shutdown") + commands+=("enable") + commands+=("disable") flags=() two_word_flags=() @@ -246,6 +271,8 @@ _gobgp_neighbor() must_have_one_flag=() must_have_one_noun=() + q_type="neighbor" + __gobgp_q_neighbor } _gobgp_policy_prefix_add() @@ -652,12 +679,14 @@ _gobgp_help() _gobgp() { + url="" + port="" + q_type="" last_command="gobgp" commands=() commands+=("global") commands+=("neighbor") commands+=("policy") - commands+=("help") flags=() two_word_flags=() -- cgit v1.2.3