]> git.ipfire.org Git - network.git/commitdiff
autocompletion: improve config part
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Mon, 24 Jul 2017 19:10:05 +0000 (21:10 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Jul 2017 16:20:57 +0000 (18:20 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/bash-completion/network

index f7c58a93359ddb0e100ef76f9295ef6d5e4b5524..820c2d41929f6c86bf6f0d356050e7b6ce858573 100644 (file)
@@ -421,20 +421,64 @@ _network_zone_subcommand_config() {
 
        local words=( $@ )
 
-       local commands="new destroy"
+       local commands="destroy list new $(network raw list-zone-config-ids ${zone})"
+
        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
                new)
                        _network_complete_hooks "config"
                        ;;
+               destroy)
+                       _network_zone_subcommand_config_destroy ${zone} ${args}
+                       ;;
+               # We use no better globbing like [:digit:] here because hids would not match the glob
+               # Also bash is silly here and does not unterstand things like ^[[:digit:]]+$ here.
+               *)
+                       # Check if we get a valid id
+                       # TODO: We should also accept a valid hid
+                       if network raw zone-config-id-is-valid ${zone} ${cmd}; then
+                               _network_zone_subcommand_config_subcommand ${zone} ${args}
+                       fi
+                       ;;
        esac
 }
 
+_network_zone_subcommand_config_subcommand() {
+       local zone="${1}"
+       shift
+
+       local words=( $@ )
+
+       local commands="edit"
+
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
+
+_network_zone_subcommand_config_destroy() {
+       local zone="${1}"
+       shift
+
+       local words=( $@ )
+
+       local commands="$(network raw list-zone-config-ids ${zone})"
+
+       local cmd="$(_network_find_on_cmdline "${commands}")"
+       if [[ -z "${cmd}" ]]; then
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+               return 0
+       fi
+}
+
 _network_zone_subcommand_port() {
        local zone="${1}"
        shift