summaryrefslogtreecommitdiffstats
path: root/src/core/parseopt.c
diff options
context:
space:
mode:
authorMichael Brown2013-11-07 18:00:51 +0100
committerMichael Brown2013-11-07 18:00:51 +0100
commit43eba2f555e2a2ed0fbedeeda73dd1720437fd97 (patch)
tree86e2decd0adbcb0e92ed8aed80b0b38023e7605a /src/core/parseopt.c
parent[ipv6] Add IPv6 network device configurator (diff)
downloadipxe-43eba2f555e2a2ed0fbedeeda73dd1720437fd97.tar.gz
ipxe-43eba2f555e2a2ed0fbedeeda73dd1720437fd97.tar.xz
ipxe-43eba2f555e2a2ed0fbedeeda73dd1720437fd97.zip
[cmdline] Generate command option help text automatically
Generate the command option help text automatically from the list of defined options. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/parseopt.c')
-rw-r--r--src/core/parseopt.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/core/parseopt.c b/src/core/parseopt.c
index 334ffb2c..d268c059 100644
--- a/src/core/parseopt.c
+++ b/src/core/parseopt.c
@@ -326,8 +326,25 @@ int parse_parameters ( char *text, struct parameters **params ) {
* @v argv Argument list
*/
void print_usage ( struct command_descriptor *cmd, char **argv ) {
- printf ( "Usage:\n\n %s %s\n\nSee http://ipxe.org/cmd/%s for further "
- "information\n", argv[0], cmd->usage, argv[0] );
+ struct option_descriptor *option;
+ unsigned int i;
+ int is_optional;
+
+ printf ( "Usage:\n\n %s", argv[0] );
+ for ( i = 0 ; i < cmd->num_options ; i++ ) {
+ option = &cmd->options[i];
+ printf ( " [-%c|--%s", option->shortopt, option->longopt );
+ if ( option->has_arg ) {
+ is_optional = ( option->has_arg == optional_argument );
+ printf ( " %s<%s>%s", ( is_optional ? "[" : "" ),
+ option->longopt, ( is_optional ? "]" : "" ) );
+ }
+ printf ( "]" );
+ }
+ if ( cmd->usage )
+ printf ( " %s", cmd->usage );
+ printf ( "\n\nSee http://ipxe.org/cmd/%s for further information\n",
+ argv[0] );
}
/**