mirror of https://github.com/ipxe/ipxe.git
[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>pull/17/head
parent
6871a8113f
commit
43eba2f555
|
@ -78,7 +78,7 @@ static struct option_descriptor stoppxe_opts[] = {};
|
|||
|
||||
/** "stoppxe" command descriptor */
|
||||
static struct command_descriptor stoppxe_cmd =
|
||||
COMMAND_DESC ( struct stoppxe_options, stoppxe_opts, 0, 0, "" );
|
||||
COMMAND_DESC ( struct stoppxe_options, stoppxe_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "stoppxe" command
|
||||
|
|
|
@ -54,8 +54,7 @@ static struct option_descriptor cpuid_opts[] = {
|
|||
|
||||
/** "cpuid" command descriptor */
|
||||
static struct command_descriptor cpuid_cmd =
|
||||
COMMAND_DESC ( struct cpuid_options, cpuid_opts, 1, 1,
|
||||
"[--ext] [--ecx] <bit>" );
|
||||
COMMAND_DESC ( struct cpuid_options, cpuid_opts, 1, 1, "<bit>" );
|
||||
|
||||
/**
|
||||
* The "cpuid" command
|
||||
|
|
|
@ -397,7 +397,7 @@ static struct option_descriptor echo_opts[] = {
|
|||
/** "echo" command descriptor */
|
||||
static struct command_descriptor echo_cmd =
|
||||
COMMAND_DESC ( struct echo_options, echo_opts, 0, MAX_ARGUMENTS,
|
||||
"[-n] [...]" );
|
||||
"[...]" );
|
||||
|
||||
/**
|
||||
* "echo" command
|
||||
|
|
|
@ -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] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -106,7 +106,7 @@ static struct option_descriptor fcstat_opts[] = {};
|
|||
|
||||
/** "fcstat" command descriptor */
|
||||
static struct command_descriptor fcstat_cmd =
|
||||
COMMAND_DESC ( struct fcstat_options, fcstat_opts, 0, 0, "" );
|
||||
COMMAND_DESC ( struct fcstat_options, fcstat_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "fcstat" command
|
||||
|
@ -151,8 +151,7 @@ static struct option_descriptor fcels_opts[] = {
|
|||
|
||||
/** "fcels" command descriptor */
|
||||
static struct command_descriptor fcels_cmd =
|
||||
COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1,
|
||||
"[--port <port>] [--id <peer port id>] <request>" );
|
||||
COMMAND_DESC ( struct fcels_options, fcels_opts, 1, 1, "<request>" );
|
||||
|
||||
/**
|
||||
* The "fcels" command
|
||||
|
|
|
@ -226,9 +226,7 @@ static int ifconf_payload ( struct net_device *netdev,
|
|||
/** "ifconf" command descriptor */
|
||||
static struct ifcommon_command_descriptor ifconf_cmd =
|
||||
IFCOMMON_COMMAND_DESC ( struct ifconf_options, ifconf_opts,
|
||||
0, MAX_ARGUMENTS,
|
||||
"[--configurator <configurator>] "
|
||||
"[<interface>...]",
|
||||
0, MAX_ARGUMENTS, "[<interface>...]",
|
||||
ifconf_payload, 1 );
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,22 +47,22 @@ struct imgsingle_options {
|
|||
};
|
||||
|
||||
/** "img{single}" option list */
|
||||
static struct option_descriptor imgsingle_opts[] = {
|
||||
OPTION_DESC ( "name", 'n', required_argument,
|
||||
struct imgsingle_options, name, parse_string ),
|
||||
OPTION_DESC ( "replace", 'r', no_argument,
|
||||
struct imgsingle_options, replace, parse_flag ),
|
||||
OPTION_DESC ( "autofree", 'a', no_argument,
|
||||
struct imgsingle_options, autofree, parse_flag ),
|
||||
static union {
|
||||
/* "imgexec" takes all three options */
|
||||
struct option_descriptor imgexec[3];
|
||||
/* Other "img{single}" commands take only --name and --autofree */
|
||||
struct option_descriptor imgsingle[2];
|
||||
} opts = {
|
||||
.imgexec = {
|
||||
OPTION_DESC ( "name", 'n', required_argument,
|
||||
struct imgsingle_options, name, parse_string ),
|
||||
OPTION_DESC ( "autofree", 'a', no_argument,
|
||||
struct imgsingle_options, autofree, parse_flag ),
|
||||
OPTION_DESC ( "replace", 'r', no_argument,
|
||||
struct imgsingle_options, replace, parse_flag ),
|
||||
},
|
||||
};
|
||||
|
||||
/** "img{single}" command descriptor */
|
||||
static struct command_descriptor imgsingle_cmd =
|
||||
COMMAND_DESC ( struct imgsingle_options, imgsingle_opts,
|
||||
1, MAX_ARGUMENTS,
|
||||
"[--name <name>] [--autofree] "
|
||||
"<uri|image> [<arguments>...]" );
|
||||
|
||||
/** An "img{single}" family command descriptor */
|
||||
struct imgsingle_descriptor {
|
||||
/** Command descriptor */
|
||||
|
@ -174,9 +174,8 @@ static int imgsingle_exec ( int argc, char **argv,
|
|||
|
||||
/** "imgfetch" command descriptor */
|
||||
static struct command_descriptor imgfetch_cmd =
|
||||
COMMAND_DESC ( struct imgsingle_options, imgsingle_opts,
|
||||
1, MAX_ARGUMENTS,
|
||||
"[--name <name>] [--autofree] <uri> [<arguments>...]" );
|
||||
COMMAND_DESC ( struct imgsingle_options, opts.imgsingle,
|
||||
1, MAX_ARGUMENTS, "<uri> [<arguments>...]" );
|
||||
|
||||
/** "imgfetch" family command descriptor */
|
||||
struct imgsingle_descriptor imgfetch_desc = {
|
||||
|
@ -207,9 +206,14 @@ static int imgselect ( struct image *image,
|
|||
return image_select ( image );
|
||||
}
|
||||
|
||||
/** "imgselect" command descriptor */
|
||||
static struct command_descriptor imgselect_cmd =
|
||||
COMMAND_DESC ( struct imgsingle_options, opts.imgsingle,
|
||||
1, MAX_ARGUMENTS, "<uri|image> [<arguments>...]" );
|
||||
|
||||
/** "imgselect" family command descriptor */
|
||||
struct imgsingle_descriptor imgselect_desc = {
|
||||
.cmd = &imgsingle_cmd,
|
||||
.cmd = &imgselect_cmd,
|
||||
.acquire = imgacquire,
|
||||
.action = imgselect,
|
||||
.verb = "select",
|
||||
|
@ -228,10 +232,8 @@ static int imgselect_exec ( int argc, char **argv ) {
|
|||
|
||||
/** "imgexec" command descriptor */
|
||||
static struct command_descriptor imgexec_cmd =
|
||||
COMMAND_DESC ( struct imgsingle_options, imgsingle_opts,
|
||||
0, MAX_ARGUMENTS,
|
||||
"[--autofree] [--replace] "
|
||||
"[<uri|image> [<arguments>...]]" );
|
||||
COMMAND_DESC ( struct imgsingle_options, opts.imgexec,
|
||||
0, MAX_ARGUMENTS, "[<uri|image> [<arguments>...]]" );
|
||||
|
||||
/**
|
||||
* "imgexec" command action
|
||||
|
@ -282,9 +284,14 @@ static int imgexec_exec ( int argc, char **argv) {
|
|||
return imgsingle_exec ( argc, argv, &imgexec_desc );
|
||||
}
|
||||
|
||||
/** "imgargs" command descriptor */
|
||||
static struct command_descriptor imgargs_cmd =
|
||||
COMMAND_DESC ( struct imgsingle_options, opts.imgsingle,
|
||||
1, MAX_ARGUMENTS, "<uri|image> [<arguments>...]" );
|
||||
|
||||
/** "imgargs" family command descriptor */
|
||||
struct imgsingle_descriptor imgargs_desc = {
|
||||
.cmd = &imgsingle_cmd,
|
||||
.cmd = &imgargs_cmd,
|
||||
.acquire = imgacquire,
|
||||
.preaction = image_clear_cmdline,
|
||||
};
|
||||
|
|
|
@ -52,8 +52,7 @@ static struct option_descriptor imgtrust_opts[] = {
|
|||
|
||||
/** "imgtrust" command descriptor */
|
||||
static struct command_descriptor imgtrust_cmd =
|
||||
COMMAND_DESC ( struct imgtrust_options, imgtrust_opts, 0, 0,
|
||||
"[--allow] [--permanent]" );
|
||||
COMMAND_DESC ( struct imgtrust_options, imgtrust_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "imgtrust" command
|
||||
|
@ -100,8 +99,7 @@ static struct option_descriptor imgverify_opts[] = {
|
|||
/** "imgverify" command descriptor */
|
||||
static struct command_descriptor imgverify_cmd =
|
||||
COMMAND_DESC ( struct imgverify_options, imgverify_opts, 2, 2,
|
||||
"[--signer <signer>] [--keep] <uri|image> "
|
||||
"<signature uri|image>" );
|
||||
"<uri|image> <signature uri|image>" );
|
||||
|
||||
/**
|
||||
* The "imgverify" command
|
||||
|
|
|
@ -39,7 +39,7 @@ static struct option_descriptor login_opts[] = {};
|
|||
|
||||
/** "login" command descriptor */
|
||||
static struct command_descriptor login_cmd =
|
||||
COMMAND_DESC ( struct login_options, login_opts, 0, 0, "" );
|
||||
COMMAND_DESC ( struct login_options, login_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* "login" command
|
||||
|
|
|
@ -50,8 +50,7 @@ static struct option_descriptor lotest_opts[] = {
|
|||
/** "lotest" command descriptor */
|
||||
static struct command_descriptor lotest_cmd =
|
||||
COMMAND_DESC ( struct lotest_options, lotest_opts, 2, 2,
|
||||
"[--mtu <mtu>] <sending interface> "
|
||||
"<receiving interface>" );
|
||||
"<sending interface> <receiving interface>" );
|
||||
|
||||
/**
|
||||
* "lotest" command
|
||||
|
|
|
@ -57,7 +57,7 @@ static struct option_descriptor menu_opts[] = {
|
|||
/** "menu" command descriptor */
|
||||
static struct command_descriptor menu_cmd =
|
||||
COMMAND_DESC ( struct menu_options, menu_opts, 0, MAX_ARGUMENTS,
|
||||
"[--name <name>] [--delete] [<title>]" );
|
||||
"[<title>]" );
|
||||
|
||||
/**
|
||||
* The "menu" command
|
||||
|
@ -131,8 +131,7 @@ static struct option_descriptor item_opts[] = {
|
|||
/** "item" command descriptor */
|
||||
static struct command_descriptor item_cmd =
|
||||
COMMAND_DESC ( struct item_options, item_opts, 0, MAX_ARGUMENTS,
|
||||
"[--menu <menu>] [--key <key>] [--default] "
|
||||
"[<label>|--gap [<text>]]" );
|
||||
"[<label> [<text>]]" );
|
||||
|
||||
/**
|
||||
* The "item" command
|
||||
|
@ -215,9 +214,7 @@ static struct option_descriptor choose_opts[] = {
|
|||
|
||||
/** "choose" command descriptor */
|
||||
static struct command_descriptor choose_cmd =
|
||||
COMMAND_DESC ( struct choose_options, choose_opts, 1, 1,
|
||||
"[--menu <menu>] [--default <label>] "
|
||||
"[--timeout <timeout>] [--keep] <setting>" );
|
||||
COMMAND_DESC ( struct choose_options, choose_opts, 1, 1, "<setting>" );
|
||||
|
||||
/**
|
||||
* The "choose" command
|
||||
|
|
|
@ -38,7 +38,7 @@ static struct option_descriptor nstat_opts[] = {};
|
|||
|
||||
/** "nstat" command descriptor */
|
||||
static struct command_descriptor nstat_cmd =
|
||||
COMMAND_DESC ( struct nstat_options, nstat_opts, 0, 0, "" );
|
||||
COMMAND_DESC ( struct nstat_options, nstat_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "nstat" command
|
||||
|
|
|
@ -50,8 +50,7 @@ static struct option_descriptor params_opts[] = {
|
|||
|
||||
/** "params" command descriptor */
|
||||
static struct command_descriptor params_cmd =
|
||||
COMMAND_DESC ( struct params_options, params_opts, 0, 0,
|
||||
"[--name <name>] [--delete]" );
|
||||
COMMAND_DESC ( struct params_options, params_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "params" command
|
||||
|
@ -96,7 +95,7 @@ static struct option_descriptor param_opts[] = {
|
|||
/** "param" command descriptor */
|
||||
static struct command_descriptor param_cmd =
|
||||
COMMAND_DESC ( struct param_options, param_opts, 1, MAX_ARGUMENTS,
|
||||
"[--params <params>] <key> [<value>]" );
|
||||
"<key> [<value>]" );
|
||||
|
||||
/**
|
||||
* The "param" command
|
||||
|
|
|
@ -60,8 +60,7 @@ static struct option_descriptor ping_opts[] = {
|
|||
|
||||
/** "ping" command descriptor */
|
||||
static struct command_descriptor ping_cmd =
|
||||
COMMAND_DESC ( struct ping_options, ping_opts, 1, 1,
|
||||
"[--size <size>] [--timeout <timeout>] <host>" );
|
||||
COMMAND_DESC ( struct ping_options, ping_opts, 1, 1, "<host>" );
|
||||
|
||||
/**
|
||||
* The "ping" command
|
||||
|
|
|
@ -40,7 +40,7 @@ static struct option_descriptor poweroff_opts[] = {};
|
|||
|
||||
/** "poweroff" command descriptor */
|
||||
static struct command_descriptor poweroff_cmd =
|
||||
COMMAND_DESC ( struct poweroff_options, poweroff_opts, 0, 0, "" );
|
||||
COMMAND_DESC ( struct poweroff_options, poweroff_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "poweroff" command
|
||||
|
|
|
@ -44,7 +44,7 @@ static struct option_descriptor reboot_opts[] = {
|
|||
|
||||
/** "reboot" command descriptor */
|
||||
static struct command_descriptor reboot_cmd =
|
||||
COMMAND_DESC ( struct reboot_options, reboot_opts, 0, 0, "[--warm]" );
|
||||
COMMAND_DESC ( struct reboot_options, reboot_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "reboot" command
|
||||
|
|
|
@ -39,7 +39,7 @@ static struct option_descriptor route_opts[] = {};
|
|||
|
||||
/** "route" command descriptor */
|
||||
static struct command_descriptor route_cmd =
|
||||
COMMAND_DESC ( struct route_options, route_opts, 0, 0, "" );
|
||||
COMMAND_DESC ( struct route_options, route_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "route" command
|
||||
|
|
|
@ -46,30 +46,38 @@ struct sanboot_options {
|
|||
};
|
||||
|
||||
/** "sanboot" option list */
|
||||
static struct option_descriptor sanboot_opts[] = {
|
||||
OPTION_DESC ( "drive", 'd', required_argument,
|
||||
struct sanboot_options, drive, parse_integer ),
|
||||
OPTION_DESC ( "no-describe", 'n', no_argument,
|
||||
struct sanboot_options, no_describe, parse_flag ),
|
||||
OPTION_DESC ( "keep", 'k', no_argument,
|
||||
struct sanboot_options, keep, parse_flag ),
|
||||
static union {
|
||||
/* "sanboot" takes all three options */
|
||||
struct option_descriptor sanboot[3];
|
||||
/* "sanhook" takes only --drive and --no-describe */
|
||||
struct option_descriptor sanhook[2];
|
||||
/* "sanunhook" takes only --drive */
|
||||
struct option_descriptor sanunhook[1];
|
||||
} opts = {
|
||||
.sanboot = {
|
||||
OPTION_DESC ( "drive", 'd', required_argument,
|
||||
struct sanboot_options, drive, parse_integer ),
|
||||
OPTION_DESC ( "no-describe", 'n', no_argument,
|
||||
struct sanboot_options, no_describe, parse_flag ),
|
||||
OPTION_DESC ( "keep", 'k', no_argument,
|
||||
struct sanboot_options, keep, parse_flag ),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/** "sanhook" command descriptor */
|
||||
static struct command_descriptor sanhook_cmd =
|
||||
COMMAND_DESC ( struct sanboot_options, sanboot_opts, 1, 1,
|
||||
"[--drive <drive>] [--no-describe] <root-path>" );
|
||||
COMMAND_DESC ( struct sanboot_options, opts.sanhook, 1, 1,
|
||||
"<root-path>" );
|
||||
|
||||
/** "sanboot" command descriptor */
|
||||
static struct command_descriptor sanboot_cmd =
|
||||
COMMAND_DESC ( struct sanboot_options, sanboot_opts, 0, 1,
|
||||
"[--drive <drive>] [--no-describe] [--keep] "
|
||||
COMMAND_DESC ( struct sanboot_options, opts.sanboot, 0, 1,
|
||||
"[<root-path>]" );
|
||||
|
||||
/** "sanunhook" command descriptor */
|
||||
static struct command_descriptor sanunhook_cmd =
|
||||
COMMAND_DESC ( struct sanboot_options, sanboot_opts, 0, 0,
|
||||
"[--drive <drive>]" );
|
||||
COMMAND_DESC ( struct sanboot_options, opts.sanunhook, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* The "sanboot", "sanhook" and "sanunhook" commands
|
||||
|
|
|
@ -46,8 +46,7 @@ static struct option_descriptor sync_opts[] = {
|
|||
|
||||
/** "sync" command descriptor */
|
||||
static struct command_descriptor sync_cmd =
|
||||
COMMAND_DESC ( struct sync_options, sync_opts, 0, 0,
|
||||
"[--timeout <timeout>]" );
|
||||
COMMAND_DESC ( struct sync_options, sync_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* "sync" command
|
||||
|
|
|
@ -53,7 +53,6 @@ static struct option_descriptor vcreate_opts[] = {
|
|||
/** "vcreate" command descriptor */
|
||||
static struct command_descriptor vcreate_cmd =
|
||||
COMMAND_DESC ( struct vcreate_options, vcreate_opts, 1, 1,
|
||||
"--tag <tag> [--priority <priority>] "
|
||||
"<trunk interface>" );
|
||||
|
||||
/**
|
||||
|
|
|
@ -107,7 +107,7 @@ static struct option_descriptor shell_opts[] = {};
|
|||
|
||||
/** "shell" command descriptor */
|
||||
static struct command_descriptor shell_cmd =
|
||||
COMMAND_DESC ( struct shell_options, shell_opts, 0, 0, "" );
|
||||
COMMAND_DESC ( struct shell_options, shell_opts, 0, 0, NULL );
|
||||
|
||||
/**
|
||||
* "shell" command
|
||||
|
|
|
@ -375,7 +375,7 @@ static struct option_descriptor prompt_opts[] = {
|
|||
/** "prompt" command descriptor */
|
||||
static struct command_descriptor prompt_cmd =
|
||||
COMMAND_DESC ( struct prompt_options, prompt_opts, 0, MAX_ARGUMENTS,
|
||||
"[--key <key>] [--timeout <timeout>] [<text>]" );
|
||||
"[<text>]" );
|
||||
|
||||
/**
|
||||
* "prompt" command
|
||||
|
|
Loading…
Reference in New Issue