Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org --- src/functions/functions.zone | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/src/functions/functions.zone b/src/functions/functions.zone index 91ce629..bba1705 100644 --- a/src/functions/functions.zone +++ b/src/functions/functions.zone @@ -641,6 +641,21 @@ zone_config_show() { zone_config_cmd "show" "$@" }
+# Returns a list of all used ids for a zone +zone_config_list_ids() { + assert [ $# -eq 1 ] + + local zone=${1} + local config + local ids + + for config in $(zone_configs_list ${zone}); do + list_append ids "$(config_get_id_from_config ${config})" + done + + echo ${ids} +} + zone_show() { local zone=${1}
This commands make it possible to list all used ids for a zone from the command line.
Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org --- src/network | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/src/network b/src/network index 3762be0..59258dd 100644 --- a/src/network +++ b/src/network @@ -1377,6 +1377,9 @@ cli_raw() { list-next-free-zones) zones_get_next_free ;; + list-zone-config-ids) + zone_config_list_ids $@ + ;; zone-name-is-valid) zone_name_is_valid $@ ;;
Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org --- src/network | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/src/network b/src/network index 59258dd..adc9ac3 100644 --- a/src/network +++ b/src/network @@ -1383,6 +1383,9 @@ cli_raw() { zone-name-is-valid) zone_name_is_valid $@ ;; + zone-config-id-is-valid) + zone_config_id_is_valid $@ + ;; *) error "No such command: ${cmd}" exit ${EXIT_ERROR}
Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org --- src/bash-completion/network | 46 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/bash-completion/network b/src/bash-completion/network index f7c58a9..820c2d4 100644 --- a/src/bash-completion/network +++ b/src/bash-completion/network @@ -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
Hi,
very good patchset!
Nothing to complain. Merged.
-Michael
On Mon, 2017-07-24 at 21:10 +0200, Jonatan Schlag wrote:
Signed-off-by: Jonatan Schlag jonatan.schlag@ipfire.org
src/functions/functions.zone | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/src/functions/functions.zone b/src/functions/functions.zone index 91ce629..bba1705 100644 --- a/src/functions/functions.zone +++ b/src/functions/functions.zone @@ -641,6 +641,21 @@ zone_config_show() { zone_config_cmd "show" "$@" } +# Returns a list of all used ids for a zone +zone_config_list_ids() {
- assert [ $# -eq 1 ]
- local zone=${1}
- local config
- local ids
- for config in $(zone_configs_list ${zone}); do
list_append ids "$(config_get_id_from_config
${config})"
- done
- echo ${ids}
+}
zone_show() { local zone=${1}