summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/arch/i386/hci/commands/pxe_cmd.c2
-rw-r--r--src/arch/x86/hci/commands/cpuid_cmd.c3
-rw-r--r--src/core/exec.c2
-rw-r--r--src/core/parseopt.c21
-rw-r--r--src/hci/commands/fcmgmt_cmd.c5
-rw-r--r--src/hci/commands/ifmgmt_cmd.c4
-rw-r--r--src/hci/commands/image_cmd.c53
-rw-r--r--src/hci/commands/image_trust_cmd.c6
-rw-r--r--src/hci/commands/login_cmd.c2
-rw-r--r--src/hci/commands/lotest_cmd.c3
-rw-r--r--src/hci/commands/menu_cmd.c9
-rw-r--r--src/hci/commands/neighbour_cmd.c2
-rw-r--r--src/hci/commands/param_cmd.c5
-rw-r--r--src/hci/commands/ping_cmd.c3
-rw-r--r--src/hci/commands/poweroff_cmd.c2
-rw-r--r--src/hci/commands/reboot_cmd.c2
-rw-r--r--src/hci/commands/route_cmd.c2
-rw-r--r--src/hci/commands/sanboot_cmd.c34
-rw-r--r--src/hci/commands/sync_cmd.c3
-rw-r--r--src/hci/commands/vlan_cmd.c1
-rw-r--r--src/hci/shell.c2
-rw-r--r--src/image/script.c2
22 files changed, 93 insertions, 75 deletions
diff --git a/src/arch/i386/hci/commands/pxe_cmd.c b/src/arch/i386/hci/commands/pxe_cmd.c
index c7cdb07f..523724ab 100644
--- a/src/arch/i386/hci/commands/pxe_cmd.c
+++ b/src/arch/i386/hci/commands/pxe_cmd.c
@@ -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
diff --git a/src/arch/x86/hci/commands/cpuid_cmd.c b/src/arch/x86/hci/commands/cpuid_cmd.c
index 98114330..c4e35d17 100644
--- a/src/arch/x86/hci/commands/cpuid_cmd.c
+++ b/src/arch/x86/hci/commands/cpuid_cmd.c
@@ -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
diff --git a/src/core/exec.c b/src/core/exec.c
index 843a51db..1c85705a 100644
--- a/src/core/exec.c
+++ b/src/core/exec.c
@@ -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
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] );
}
/**
diff --git a/src/hci/commands/fcmgmt_cmd.c b/src/hci/commands/fcmgmt_cmd.c
index 99f76113..1c199b5d 100644
--- a/src/hci/commands/fcmgmt_cmd.c
+++ b/src/hci/commands/fcmgmt_cmd.c
@@ -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
diff --git a/src/hci/commands/ifmgmt_cmd.c b/src/hci/commands/ifmgmt_cmd.c
index f3d00ca3..5307c942 100644
--- a/src/hci/commands/ifmgmt_cmd.c
+++ b/src/hci/commands/ifmgmt_cmd.c
@@ -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 );
/**
diff --git a/src/hci/commands/image_cmd.c b/src/hci/commands/image_cmd.c
index 17e22dcb..dc30b3f2 100644
--- a/src/hci/commands/image_cmd.c
+++ b/src/hci/commands/image_cmd.c
@@ -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,
};
diff --git a/src/hci/commands/image_trust_cmd.c b/src/hci/commands/image_trust_cmd.c
index ad238bff..ef4bbfa8 100644
--- a/src/hci/commands/image_trust_cmd.c
+++ b/src/hci/commands/image_trust_cmd.c
@@ -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
diff --git a/src/hci/commands/login_cmd.c b/src/hci/commands/login_cmd.c
index bc23e6ff..f5db427d 100644
--- a/src/hci/commands/login_cmd.c
+++ b/src/hci/commands/login_cmd.c
@@ -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
diff --git a/src/hci/commands/lotest_cmd.c b/src/hci/commands/lotest_cmd.c
index 92f08887..0fa031bc 100644
--- a/src/hci/commands/lotest_cmd.c
+++ b/src/hci/commands/lotest_cmd.c
@@ -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
diff --git a/src/hci/commands/menu_cmd.c b/src/hci/commands/menu_cmd.c
index 6ff30083..66a6262e 100644
--- a/src/hci/commands/menu_cmd.c
+++ b/src/hci/commands/menu_cmd.c
@@ -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
diff --git a/src/hci/commands/neighbour_cmd.c b/src/hci/commands/neighbour_cmd.c
index d65c355c..a1e05243 100644
--- a/src/hci/commands/neighbour_cmd.c
+++ b/src/hci/commands/neighbour_cmd.c
@@ -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
diff --git a/src/hci/commands/param_cmd.c b/src/hci/commands/param_cmd.c
index 1b466cda..a30c62af 100644
--- a/src/hci/commands/param_cmd.c
+++ b/src/hci/commands/param_cmd.c
@@ -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
diff --git a/src/hci/commands/ping_cmd.c b/src/hci/commands/ping_cmd.c
index 4959f6a0..d514a2a2 100644
--- a/src/hci/commands/ping_cmd.c
+++ b/src/hci/commands/ping_cmd.c
@@ -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
diff --git a/src/hci/commands/poweroff_cmd.c b/src/hci/commands/poweroff_cmd.c
index 159fe618..9d487d33 100644
--- a/src/hci/commands/poweroff_cmd.c
+++ b/src/hci/commands/poweroff_cmd.c
@@ -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
diff --git a/src/hci/commands/reboot_cmd.c b/src/hci/commands/reboot_cmd.c
index 44dcfc71..485939e4 100644
--- a/src/hci/commands/reboot_cmd.c
+++ b/src/hci/commands/reboot_cmd.c
@@ -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
diff --git a/src/hci/commands/route_cmd.c b/src/hci/commands/route_cmd.c
index 3b51f06b..cc5ffc2f 100644
--- a/src/hci/commands/route_cmd.c
+++ b/src/hci/commands/route_cmd.c
@@ -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
diff --git a/src/hci/commands/sanboot_cmd.c b/src/hci/commands/sanboot_cmd.c
index 14055a8c..5954b632 100644
--- a/src/hci/commands/sanboot_cmd.c
+++ b/src/hci/commands/sanboot_cmd.c
@@ -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
diff --git a/src/hci/commands/sync_cmd.c b/src/hci/commands/sync_cmd.c
index 3c9ef2a4..adf7e3cc 100644
--- a/src/hci/commands/sync_cmd.c
+++ b/src/hci/commands/sync_cmd.c
@@ -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
diff --git a/src/hci/commands/vlan_cmd.c b/src/hci/commands/vlan_cmd.c
index 822e5dcf..5d729822 100644
--- a/src/hci/commands/vlan_cmd.c
+++ b/src/hci/commands/vlan_cmd.c
@@ -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>" );
/**
diff --git a/src/hci/shell.c b/src/hci/shell.c
index b6208676..c1a54384 100644
--- a/src/hci/shell.c
+++ b/src/hci/shell.c
@@ -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
diff --git a/src/image/script.c b/src/image/script.c
index 8d80241d..5328da8b 100644
--- a/src/image/script.c
+++ b/src/image/script.c
@@ -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