]> git.ipfire.org Git - people/ms/network.git/commitdiff
bash-completion: Add some basic completion for DHCP servers
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jan 2015 22:39:33 +0000 (22:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Jan 2015 22:39:33 +0000 (22:39 +0000)
src/bash-completion/network
src/functions/functions.dhcpd
src/network

index 8c3ec1b807845bcd55101cb8c0f2236a3261c7d5..143295c8131fdade48d76924340cde6ebbc64ba5 100644 (file)
@@ -86,6 +86,121 @@ function _network_device_subcommand() {
        esac
 }
 
+function _network_dhcpd() {
+       local proto="${1}"
+       shift
+
+       local words=( $@ )
+
+       local commands="edit reload restart show start stop subnet"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               subnet)
+                       _network_dhcpd_subnet "${proto}" ${args}
+                       ;;
+       esac
+}
+
+function _network_dhcpd_subnet() {
+       local proto="${1}"
+       shift
+
+       local words=( $@ )
+
+       local commands="new remove show $(network raw list-dhcpd-subnets "${proto}")"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+       local subnet="${words[0]}"
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               new)
+                       : # TODO
+                       ;;
+               remove)
+                       : # TODO
+                       ;;
+               [0-9]*)
+                       _network_dhcpd_subnet_subcommand "${proto}" "${subnet}" ${args}
+                       ;;
+       esac
+}
+
+function _network_dhcpd_subnet_subcommand() {
+       local proto="${1}"
+       local subnet="${2}"
+       shift 2
+
+       local words=( $@ )
+
+       local commands="edit options range show"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+       local args="${words[@]:1}"
+       case "${cmd}" in
+               edit)
+                       : # TODO
+                       ;;
+               options)
+                       _network_dhcpd_subnet_subcommand_options "${proto}" "${subnet}" ${args}
+                       ;;
+               range)
+                       _network_dhcpd_subnet_subcommand_range "${proto}" "${subnet}" ${args}
+                       ;;
+       esac
+}
+
+function _network_dhcpd_subnet_subcommand_options() {
+       local proto="${1}"
+       local subnet="${2}"
+       shift 2
+
+       local options option
+       for option in $(network raw list-dhcpd-subnet-options "${proto}"); do
+               options="${options} ${option}="
+       done
+
+       COMPREPLY=( $(compgen -W "${options}" -- "${cur}") )
+}
+
+function _network_dhcpd_subnet_subcommand_range() {
+       local proto="${1}"
+       local subnet="${2}"
+       shift 2
+
+       local words=( $@ )
+
+       local commands="new remove"
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+
+       case "${cmd}" in
+               new)
+                       COMPREPLY=( $(compgen -W "--end= --start=" -- "${cur}") )
+                       ;;
+               remove)
+                       COMPREPLY=( $(compgen -W "$(network raw list-dhcpd-ranges-of-subnet "${proto}" "${subnet}")" \
+                               -- "${cur}") )
+                       ;;
+       esac
+}
+
 function _network_dns_server() {
        local words=( $@ )
 
@@ -292,8 +407,9 @@ function _network() {
                                COMPREPLY=( $(compgen -W "--debug" -- "${cur}") )
                                ;;
                        *)
-                               COMPREPLY=( $(compgen -W "device dns-server help hostname \
-                                       port reset route settings status zone" -- "${cur}") )
+                               COMPREPLY=( $(compgen -W "device dhcpv4 dhcpv6 dns-server \
+                                       help hostname port reset route settings status zone" \
+                                       -- "${cur}") )
                                ;;
                esac
 
@@ -305,6 +421,9 @@ function _network() {
                device)
                        _network_device ${args}
                        ;;
+               dhcpv[64])
+                       _network_dhcpd "${cmd/dhcpv/ipv}" ${args}
+                       ;;
                dns-server)
                        _network_dns_server ${args}
                        ;;
index 828ad04baaf76df71bb29694637213aeb7bc70b1..f6732db33f5e0539323ede03b6d18005509b2be8 100644 (file)
@@ -332,6 +332,13 @@ function dhcpd_options() {
        return ${EXIT_OK}
 }
 
+function dhcpd_global_settings_list() {
+       local proto="${1}"
+       assert isset proto
+
+       dhcpd_settings "${proto}"
+}
+
 function dhcpd_global_settings_defaults() {
        local proto=${1}
        assert isset proto
@@ -842,21 +849,7 @@ function dhcpd_subnet_options_file() {
 
 function dhcpd_subnet_options_list() {
        local proto=${1}
-
-       case "${proto}" in
-               ipv6)
-                       print "DHCPV6D_SUBNET_OPTIONS"
-                       ;;
-               ipv4)
-                       print "DHCPV4D_SUBNET_OPTIONS"
-                       ;;
-       esac
-
-       return ${EXIT_OK}
-}
-
-function dhcpd_subnet_options() {
-       local proto=${1}
+       assert isset proto
 
        case "${proto}" in
                ipv6)
index 01b43fcfa4be63a258cee9df257ac7b34cb65da5..867e3a8b433aa957cc7d77b2a829969890366f48 100644 (file)
@@ -996,7 +996,7 @@ function cli_dhcpd_subnet_show() {
                cli_headline $(( ${level} + 2 )) "Options"
 
                local option
-               for option in $(dhcpd_subnet_options ${proto}); do
+               for option in $(dhcpd_subnet_options_list ${proto}); do
                        [ -n "${options[${option}]}" ] || continue
 
                        cli_print_fmt1 $(( ${level} + 2 )) \
@@ -1024,7 +1024,7 @@ function cli_dhcpd_subnet_show() {
        cli_space
 }
 
-function cli_dhcpd_options() {
+function cli_dhcpd_subnet_options() {
        local proto=${1}
        assert isset proto
        shift
@@ -1033,8 +1033,6 @@ function cli_dhcpd_options() {
        assert isset subnet_id
        shift
 
-       local valid_options=$(dhcpd_subnet_options ${proto})
-
        local key val
        while [ $# -gt 0 ]; do
                case "${1}" in
@@ -1253,6 +1251,18 @@ function cli_raw() {
                list-devices)
                        device_list
                        ;;
+               list-dhcpd-ranges-of-subnet)
+                       dhcpd_subnet_range_list $@
+                       ;;
+               list-dhcpd-settings)
+                       dhcpd_global_settings_list $@
+                       ;;
+               list-dhcpd-subnets)
+                       dhcpd_subnet_list $@
+                       ;;
+               list-dhcpd-subnet-options)
+                       dhcpd_subnet_options_list $@
+                       ;;
                list-dns-servers)
                        dns_server_list
                        ;;