summaryrefslogtreecommitdiffstats
path: root/src/hci/commands/image_cmd.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/hci/commands/image_cmd.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/hci/commands/image_cmd.c')
-rw-r--r--src/hci/commands/image_cmd.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/hci/commands/image_cmd.c b/src/hci/commands/image_cmd.c
index 17e22dcba..dc30b3f24 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,
};