]> git.ipfire.org Git - people/ms/network.git/commitdiff
bash-completion: Add route and dns-server commands
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Dec 2014 02:05:27 +0000 (02:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 30 Dec 2014 02:05:27 +0000 (02:05 +0000)
src/bash-completion/network
src/functions/functions.dns
src/network

index ad6bd95844d8d1bd7f5f9abe16cfd7cba1c327fc..8c3ec1b807845bcd55101cb8c0f2236a3261c7d5 100644 (file)
@@ -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}
                        ;;
index 5f2e370fd1884c9dae9b1638cd246249ac7037d6..28db4b3900c7a97652c092767713d3a821b5bf4e 100644 (file)
@@ -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
index ebd1b5c2912ac3dd922a14340c26ba03dc42eb8b..01b43fcfa4be63a258cee9df257ac7b34cb65da5 100644 (file)
@@ -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
                        ;;