* [PATCH 1/4] zone: add new function zone_config_list_ids
@ 2017-07-24 19:10 Jonatan Schlag
2017-07-24 19:10 ` [PATCH 2/4] network: add new raw command list-zone-config-ids Jonatan Schlag
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Jonatan Schlag @ 2017-07-24 19:10 UTC (permalink / raw)
To: network
[-- Attachment #1: Type: text/plain, Size: 725 bytes --]
Signed-off-by: Jonatan Schlag <jonatan.schlag(a)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}
--
2.6.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/4] network: add new raw command list-zone-config-ids
2017-07-24 19:10 [PATCH 1/4] zone: add new function zone_config_list_ids Jonatan Schlag
@ 2017-07-24 19:10 ` Jonatan Schlag
2017-07-24 19:10 ` [PATCH 3/4] network: add new raw command zone-config-id-is-valid Jonatan Schlag
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jonatan Schlag @ 2017-07-24 19:10 UTC (permalink / raw)
To: network
[-- Attachment #1: Type: text/plain, Size: 528 bytes --]
This commands make it possible to list all used ids
for a zone from the command line.
Signed-off-by: Jonatan Schlag <jonatan.schlag(a)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 $@
;;
--
2.6.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] network: add new raw command zone-config-id-is-valid
2017-07-24 19:10 [PATCH 1/4] zone: add new function zone_config_list_ids Jonatan Schlag
2017-07-24 19:10 ` [PATCH 2/4] network: add new raw command list-zone-config-ids Jonatan Schlag
@ 2017-07-24 19:10 ` Jonatan Schlag
2017-07-24 19:10 ` [PATCH 4/4] autocompletion: improve config part Jonatan Schlag
2017-07-25 16:23 ` [PATCH 1/4] zone: add new function zone_config_list_ids Michael Tremer
3 siblings, 0 replies; 5+ messages in thread
From: Jonatan Schlag @ 2017-07-24 19:10 UTC (permalink / raw)
To: network
[-- Attachment #1: Type: text/plain, Size: 456 bytes --]
Signed-off-by: Jonatan Schlag <jonatan.schlag(a)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}
--
2.6.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] autocompletion: improve config part
2017-07-24 19:10 [PATCH 1/4] zone: add new function zone_config_list_ids Jonatan Schlag
2017-07-24 19:10 ` [PATCH 2/4] network: add new raw command list-zone-config-ids Jonatan Schlag
2017-07-24 19:10 ` [PATCH 3/4] network: add new raw command zone-config-id-is-valid Jonatan Schlag
@ 2017-07-24 19:10 ` Jonatan Schlag
2017-07-25 16:23 ` [PATCH 1/4] zone: add new function zone_config_list_ids Michael Tremer
3 siblings, 0 replies; 5+ messages in thread
From: Jonatan Schlag @ 2017-07-24 19:10 UTC (permalink / raw)
To: network
[-- Attachment #1: Type: text/plain, Size: 2083 bytes --]
Signed-off-by: Jonatan Schlag <jonatan.schlag(a)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
--
2.6.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/4] zone: add new function zone_config_list_ids
2017-07-24 19:10 [PATCH 1/4] zone: add new function zone_config_list_ids Jonatan Schlag
` (2 preceding siblings ...)
2017-07-24 19:10 ` [PATCH 4/4] autocompletion: improve config part Jonatan Schlag
@ 2017-07-25 16:23 ` Michael Tremer
3 siblings, 0 replies; 5+ messages in thread
From: Michael Tremer @ 2017-07-25 16:23 UTC (permalink / raw)
To: network
[-- Attachment #1: Type: text/plain, Size: 911 bytes --]
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(a)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}
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-07-25 16:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-24 19:10 [PATCH 1/4] zone: add new function zone_config_list_ids Jonatan Schlag
2017-07-24 19:10 ` [PATCH 2/4] network: add new raw command list-zone-config-ids Jonatan Schlag
2017-07-24 19:10 ` [PATCH 3/4] network: add new raw command zone-config-id-is-valid Jonatan Schlag
2017-07-24 19:10 ` [PATCH 4/4] autocompletion: improve config part Jonatan Schlag
2017-07-25 16:23 ` [PATCH 1/4] zone: add new function zone_config_list_ids Michael Tremer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox