]> git.ipfire.org Git - people/ms/network.git/commitdiff
Add CLI commands to view help for hooks.
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 7 Jun 2012 20:51:06 +0000 (20:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 7 Jun 2012 20:51:06 +0000 (20:51 +0000)
header-zone
man/network.8.in
network

index e2548fab5cd752769e8845d315e8b106843a0a96..0c25a1aae132d8a3e78d2ec442d74cc58dca410a 100644 (file)
@@ -24,7 +24,7 @@
 #     conflict with any functions that were defined somewhere else.
 #
 
-. /lib/network/functions
+. /usr/lib/network/functions
 
 HOOK=$(basename ${0})
 
@@ -100,6 +100,17 @@ function _discover() {
        exit ${DISCOVER_NOT_SUPPORTED}
 }
 
+# The default help function.
+function _help() {
+       # If no man page has been configured, we print an error message.
+       if [ -z "${HOOK_MANPAGE}" ]; then
+               error "There is no help available for hook '${HOOK}'. Exiting."
+               exit ${EXIT_ERROR}
+       fi
+
+       cli_show_man ${HOOK_MANPAGE}
+}
+
 # Do nothing
 function _parse_cmdline() {
        return ${EXIT_OK}
@@ -352,6 +363,11 @@ function run() {
                        _${action} $@
                        ;;
 
+               # Help requested by the user.
+               help)
+                       _help $@
+                       ;;
+
                *)
                        error "Unknown action: ${action}"
                        ;;              
index e2c6693840464fb11026387b7935e45693af4763..e8f5267767d548f08b92f24ccf18eb287407871f 100644 (file)
@@ -86,6 +86,16 @@ You may set them by appending a new setting to the command line.
 .RE
 .PP
 
+\fBhelp [<type> <hook>]\fR
+.RS 4
+Running "network help" without any arguments will show you this man page.
+.PP
+You may optionally give two arguments, to view the help of a certain hook.
+The type of the hook (\fB<type>\fR) needs to be passed as well as the
+name of the hook (\fB<hook>\fR).
+.RE
+.PP
+
 \fBhostname [new-hostname]\fR
 .RS 4
 The \fBhostname\fR command will return the currently configured hostname of the system.
diff --git a/network b/network
index 614efcf1f96710211bd0a9b9e5e4d82ce4f0f86f..dbd5dabf590adfd102422c5be333dcc358b25417 100755 (executable)
--- a/network
+++ b/network
@@ -520,6 +520,32 @@ function cli_reset() {
        exit ${EXIT_OK}
 }
 
+# Help function: will show the default man page to the user.
+# Optionally, there are two arguments taken, the type of hook
+# and which hook should be shown.
+function cli_help() {
+       local type=${1}
+       local what=${2}
+
+       # Remove unknown types.
+       if ! listmatch ${type} zone port config; then
+               type=""
+       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} ${what}; then
+               error "Hook of type '${type}' and name '${what}' could not be found."
+               exit "${EXIT_ERROR}"
+       fi
+
+       hook_exec ${type} ${what} help
+}
+
 # Process the given action
 case "${action}" in
        init)
@@ -531,8 +557,7 @@ case "${action}" in
                ;;
 
        ""|help|--help|-h)
-               cli_show_man network
-               exit ${EXIT_OK}
+               cli_help $@
                ;;
 
        *)
@@ -541,3 +566,5 @@ case "${action}" in
                exit ${EXIT_CONF_ERROR}
                ;;
 esac
+
+exit ${EXIT_OK}