]> git.ipfire.org Git - network.git/commitdiff
improve autocompletion of network zone new
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 7 Jun 2017 06:20:28 +0000 (08:20 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Jun 2017 16:32:17 +0000 (18:32 +0200)
Fixes: #11386
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/bash-completion/network
src/functions/functions.zone
src/network

index ae358bdcb750b67dd25229eb09639ed108e5bada..4b5e34d30bea82125c946ab9c7592e3138cca071 100644 (file)
@@ -318,11 +318,11 @@ _network_zone() {
                return 0
        fi
 
+
        local args="${words[@]:1}"
        case "${cmd}" in
                new)
-                       # TODO
-                       return 0
+                       _network_zone_new ${args}
                        ;;
                destroy)
                        _network_complete_zones
@@ -335,6 +335,24 @@ _network_zone() {
        esac
 }
 
+_network_zone_new() {
+       local words=( $@ )
+       local cmd=${words[@]:0:1}
+
+       # Suggest useful zone names
+       if [[ -z "${cmd}" ]]; then
+               local commands="$(network raw list-next-free-zones)"
+               COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+
+       # If a valid zone name was entered, we can move on
+       elif network raw zone-name-is-valid ${cmd}; then
+               local args="${words[@]:1}"
+               _network_complete_hooks zone ${args}
+       fi
+
+       return 0
+}
+
 _network_zone_subcommand() {
        local zone="${1}"
        shift
index c72750601ef96f05496e61ed4c619ba97d30b6b5..88c81a86181add8de65e8ffa275c3f5c4161c69d 100644 (file)
@@ -629,6 +629,26 @@ zones_get_all() {
        done
 }
 
+zones_get_next_free() {
+       # This function return the next free zones.
+       # Example net0 upl0 upl1 are configured so the next free zones are:
+       # net1 upl2
+       local i
+       local zone_name
+       for zone_name in ${VALID_ZONES}; do
+               i=0
+
+               while true; do
+                       local zone="${zone_name}${i}"
+                       if ! zone_exists ${zone}; then
+                               echo "${zone}"
+                               break
+                       fi
+                       i=$(( i + 1 ))
+               done
+       done
+}
+
 zones_get_local() {
        local zone
        for zone in $(zones_get_all); do
index 4d5955fa78c408a7f33566d76f341443df8db7de..e1934b850823ff330778f4cf03a11b09cfdbdee6 100644 (file)
@@ -1350,6 +1350,12 @@ cli_raw() {
                list-zones)
                        zones_get_all
                        ;;
+               list-next-free-zones)
+                       zones_get_next_free
+                       ;;
+               zone-name-is-valid)
+                       zone_name_is_valid $@
+                       ;;
                *)
                        error "No such command: ${cmd}"
                        exit ${EXIT_ERROR}