From: Michael Tremer Date: Thu, 7 Jun 2012 20:51:06 +0000 (+0000) Subject: Add CLI commands to view help for hooks. X-Git-Tag: 004~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85afd7750e455c85ae8e1914e32a56daef0f2b82;p=network.git Add CLI commands to view help for hooks. --- diff --git a/header-zone b/header-zone index e2548fab..0c25a1aa 100644 --- a/header-zone +++ b/header-zone @@ -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}" ;; diff --git a/man/network.8.in b/man/network.8.in index e2c66938..e8f52677 100644 --- a/man/network.8.in +++ b/man/network.8.in @@ -86,6 +86,16 @@ You may set them by appending a new setting to the command line. .RE .PP +\fBhelp [ ]\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\fR) needs to be passed as well as the +name of the hook (\fB\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 614efcf1..dbd5dabf 100755 --- 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}