From 6b7654ebc51512910a96e5eac7b0f0254c50bac8 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 15 Sep 2016 22:50:33 +0200 Subject: [PATCH] Move list-hooks command as sub-command of help Fixes #11181 Signed-off-by: Michael Tremer --- man/network-zone.xml | 16 ---------------- man/network.xml | 7 ++++++- src/network | 45 +++++++++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/man/network-zone.xml b/man/network-zone.xml index acf4530d..cd7017a3 100644 --- a/man/network-zone.xml +++ b/man/network-zone.xml @@ -32,10 +32,6 @@ network zone [new|destroy] ZONE ... - - network zone list-hooks - - network zone ZONE command ... @@ -100,18 +96,6 @@ - - - - list-hooks - - - - - Outputs a list of all eligible hooks for the zones. - - - diff --git a/man/network.xml b/man/network.xml index 90ab27cf..f40ad843 100644 --- a/man/network.xml +++ b/man/network.xml @@ -205,7 +205,8 @@ - help [TYPE HOOK] + help [TYPE + HOOK|TYPE list-hooks] @@ -213,6 +214,10 @@ Calling network help without any arguments will show you this man page. + + network help TYPE list-hooks + will print a list of all hooks of TYPE. + You may optionally pass two arguments, to view the help of a certain hook. diff --git a/src/network b/src/network index 719664e5..e65eb6bf 100644 --- a/src/network +++ b/src/network @@ -586,9 +586,6 @@ cli_zone() { destroy) cli_zone_destroy $@ ;; - list-hooks) - cli_list_hooks zone $@ - ;; ""|*) if [ -n "${action}" ]; then error "Unrecognized argument: '${action}'" @@ -1192,26 +1189,36 @@ cli_reset() { # Optionally, there are two arguments taken, the type of hook # and which hook should be shown. cli_help() { - local type=${1} - local what=${2} + local cmd=${1} + shift - # Remove unknown types. - if ! listmatch ${type} zone port config; then - type="" - fi + case "${cmd}" in + zone|port|config) + local type=${cmd} + local hook=${1} + + # List all hooks if requested + if [ "${hook}" = "list-hooks" ]; then + cli_list_hooks ${type} + return ${EXIT_OK} + fi - # If no arguments were given, we will show the default page. - if [ -z "${type}" ]; then - cli_show_man network - return ${EXIT_OK} - fi + if ! hook_exists ${type} ${hook}; then + error "No hook with name '${hook}' could be found" + exit "${EXIT_ERROR}" + fi - if ! hook_exists ${type} ${what}; then - error "Hook of type '${type}' and name '${what}' could not be found." - exit "${EXIT_ERROR}" - fi + hook_exec ${type} ${hook} help + ;; + + # In all other cases show the default man page + *) + cli_show_man network + return ${EXIT_OK} + ;; + esac - hook_exec ${type} ${what} help + return ${EXIT_ERROR} } cli_dns_server() { -- 2.39.2