From 8d1d27454e5f3357048c4c40c808294e776b6fc7 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 30 Dec 2014 02:05:27 +0000 Subject: [PATCH] bash-completion: Add route and dns-server commands --- src/bash-completion/network | 56 +++++++++++++++++++++++++++++++++---- src/functions/functions.dns | 26 +++++++++++++---- src/network | 5 +++- 3 files changed, 75 insertions(+), 12 deletions(-) diff --git a/src/bash-completion/network b/src/bash-completion/network index ad6bd958..8c3ec1b8 100644 --- a/src/bash-completion/network +++ b/src/bash-completion/network @@ -74,10 +74,8 @@ function _network_device_subcommand() { local commands="discover monitor status unlock ussd" local cmd="$(_network_find_on_cmdline "${commands}")" - if [[ -z "${cmd}" ]]; then - COMPREPLY=( $(compgen -W "discover monitor status unlock ussd" \ - -- "${cur}") ) + COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) return 0 fi @@ -88,6 +86,24 @@ function _network_device_subcommand() { esac } +function _network_dns_server() { + local words=( $@ ) + + local commands="add list remove update" + local cmd="$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi + + case "${cmd}" in + remove) + COMPREPLY=( $(compgen -W "$(network raw list-dns-servers)" \ + -- "${cur}") ) + ;; + esac +} + function _network_port() { local words=( $@ ) @@ -124,6 +140,30 @@ function _network_port_subcommand() { fi } +function _network_route() { + local words=( $@ ) + + local commands="add list remove" + local cmd="$(_network_find_on_cmdline "${commands}")" + if [[ -z "${cmd}" ]]; then + COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) + return 0 + fi + + case "${cmd}" in + add) + if [[ "${cur}" = -* ]]; then + COMPREPLY=( $(compgen -W "--blackhole --gateway= --mtu= \ + --prohibit --unreachable" -- "${cur}") ) + fi + ;; + list) + # TODO auto-complete options like --protocol here + COMPREPLY=( $(compgen -W "--protocol=" -- "${cur}") ) + ;; + esac +} + function _network_settings() { local words=( $@ ) @@ -252,8 +292,8 @@ function _network() { COMPREPLY=( $(compgen -W "--debug" -- "${cur}") ) ;; *) - COMPREPLY=( $(compgen -W "device hostname port settings status zone" \ - -- "${cur}") ) + COMPREPLY=( $(compgen -W "device dns-server help hostname \ + port reset route settings status zone" -- "${cur}") ) ;; esac @@ -265,9 +305,15 @@ function _network() { device) _network_device ${args} ;; + dns-server) + _network_dns_server ${args} + ;; port) _network_port ${args} ;; + route) + _network_route ${args} + ;; settings) _network_settings ${args} ;; diff --git a/src/functions/functions.dns b/src/functions/functions.dns index 5f2e370f..28db4b39 100644 --- a/src/functions/functions.dns +++ b/src/functions/functions.dns @@ -61,14 +61,10 @@ function dns_server_list() { local line local ${NETWORK_CONFIG_DNS_SERVER_PARAMS} - - local format="%-20s %-8s" - print "${format}" "SERVER" "PRIORITY" - - while read -r line; do + while read line; do dns_server_parse_line ${line} || continue - print "${format}" "${server}" "${priority}" + print "${server}" done < ${DNS_SERVER_CONFIG_FILE} return ${EXIT_OK} @@ -108,6 +104,24 @@ function dns_server_list_sorted() { return ${EXIT_OK} } +function dns_server_show() { + [ -r "${DNS_SERVER_CONFIG_FILE}" ] || return ${EXIT_OK} + + local line + local ${NETWORK_CONFIG_DNS_SERVER_PARAMS} + + local format="%-20s %-8s" + print "${format}" "SERVER" "PRIORITY" + + while read -r line; do + dns_server_parse_line ${line} || continue + + print "${format}" "${server}" "${priority}" + done < ${DNS_SERVER_CONFIG_FILE} + + return ${EXIT_OK} +} + function dns_server_add() { local server=${1} assert isset server diff --git a/src/network b/src/network index ebd1b5c2..01b43fcf 100644 --- a/src/network +++ b/src/network @@ -1208,7 +1208,7 @@ function cli_dns_server() { case "${cmd}" in list) - dns_server_list + dns_server_show exit ${EXIT_OK} ;; add) @@ -1253,6 +1253,9 @@ function cli_raw() { list-devices) device_list ;; + list-dns-servers) + dns_server_list + ;; list-free-ports) port_list_free ;; -- 2.39.2