Just like --long-options, it makes it possible to know which short
options are supported by each tool; this can help improving the bash
completion, for example.
---
align/scan.c | 3 +++
builder/cmdline.ml | 1 +
cat/cat.c | 3 +++
cat/filesystems.c | 3 +++
cat/log.c | 3 +++
cat/ls.c | 3 +++
customize/customize_main.ml | 1 +
df/main.c | 3 +++
diff/diff.c | 3 +++
edit/edit.c | 3 +++
fish/fish.c | 3 +++
fish/options.c | 16 +++++++++++++++-
fish/options.h | 1 +
format/format.c | 3 +++
fuse/guestmount.c | 3 +++
inspector/inspector.c | 3 +++
make-fs/make-fs.c | 4 ++++
mllib/common_utils.ml | 9 ++++++++-
mllib/common_utils.mli | 2 ++
p2v/main.c | 17 ++++++++++++++++-
rescue/rescue.c | 3 +++
resize/resize.ml | 1 +
sparsify/cmdline.ml | 1 +
sysprep/main.ml | 1 +
v2v/cmdline.ml | 1 +
25 files changed, 91 insertions(+), 3 deletions(-)
diff --git a/align/scan.c b/align/scan.c
index e803d8e..7da468f 100644
--- a/align/scan.c
+++ b/align/scan.c
@@ -115,6 +115,7 @@ main (int argc, char *argv[])
{ "help", 0, 0, HELP_OPTION },
{ "long-options", 0, 0, 0 },
{ "quiet", 0, 0, 'q' },
+ { "short-options", 0, 0, 0 },
{ "uuid", 0, 0, 0, },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
@@ -143,6 +144,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
} else if (STREQ (long_options[option_index].name, "uuid")) {
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index e21d5bb..bb7b1d0 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -135,6 +135,7 @@ let parse_cmdline () =
"--long", Arg.Unit list_set_long, " " ^ s_"Shortcut
for --list-format short";
"--list-format", Arg.String list_set_format,
"short|long|json" ^ " " ^
s_"Set the format for --list (default: short)";
+ "--short-options", Arg.Unit display_short_options, " " ^
s_"List short options";
"--long-options", Arg.Unit display_long_options, " " ^
s_"List long options";
"--machine-readable", Arg.Set machine_readable, " " ^
s_"Make output machine readable";
"-m",
Arg.Int set_memsize, "mb" ^ " " ^
s_"Set memory size";
diff --git a/cat/cat.c b/cat/cat.c
index ec9c81f..fdfa3a9 100644
--- a/cat/cat.c
+++ b/cat/cat.c
@@ -99,6 +99,7 @@ main (int argc, char *argv[])
{ "keys-from-stdin", 0, 0, 0 },
{ "long-options", 0, 0, 0 },
{ "mount", 1, 0, 'm' },
+ { "short-options", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
@@ -128,6 +129,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
} else if (STREQ (long_options[option_index].name, "echo-keys")) {
diff --git a/cat/filesystems.c b/cat/filesystems.c
index f9f887a..79d12bd 100644
--- a/cat/filesystems.c
+++ b/cat/filesystems.c
@@ -164,6 +164,7 @@ main (int argc, char *argv[])
{ "physical-volumes", 0, 0, 0 },
{ "physvols", 0, 0, 0 },
{ "pvs", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "uuid", 0, 0, 0 },
{ "uuids", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
@@ -197,6 +198,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
} else if (STREQ (long_options[option_index].name, "echo-keys")) {
diff --git a/cat/log.c b/cat/log.c
index 0d8dab0..9e8a7bf 100644
--- a/cat/log.c
+++ b/cat/log.c
@@ -105,6 +105,7 @@ main (int argc, char *argv[])
{ "help", 0, 0, HELP_OPTION },
{ "keys-from-stdin", 0, 0, 0 },
{ "long-options", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
@@ -130,6 +131,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
} else if (STREQ (long_options[option_index].name, "echo-keys")) {
diff --git a/cat/ls.c b/cat/ls.c
index 2cb4e74..b979928 100644
--- a/cat/ls.c
+++ b/cat/ls.c
@@ -151,6 +151,7 @@ main (int argc, char *argv[])
{ "long-options", 0, 0, 0 },
{ "mount", 1, 0, 'm' },
{ "recursive", 0, 0, 'R' },
+ { "short-options", 0, 0, 0 },
{ "time", 0, 0, 0 },
{ "times", 0, 0, 0 },
{ "time-days", 0, 0, 0 },
@@ -190,6 +191,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
} else if (STREQ (long_options[option_index].name, "echo-keys")) {
diff --git a/customize/customize_main.ml b/customize/customize_main.ml
index 2830e8d..5bba71a 100644
--- a/customize/customize_main.ml
+++ b/customize/customize_main.ml
@@ -93,6 +93,7 @@ let main () =
"--dry-run", Arg.Set dryrun, " " ^ s_"Perform a
dry run";
"--format", Arg.String set_format, s_"format" ^ "
" ^ s_"Set format (default: auto)";
"--long-options", Arg.Unit display_long_options, " " ^
s_"List long options";
+ "--short-options", Arg.Unit display_short_options, " " ^
s_"List short options";
"-m",
Arg.Int set_memsize, "mb" ^ " " ^
s_"Set memory size";
"--memsize",
Arg.Int set_memsize, "mb" ^ " " ^
s_"Set memory size";
"--network", Arg.Set network, " " ^ s_"Enable
appliance network (default)";
diff --git a/df/main.c b/df/main.c
index bddf2a9..09a58eb 100644
--- a/df/main.c
+++ b/df/main.c
@@ -115,6 +115,7 @@ main (int argc, char *argv[])
{ "inodes", 0, 0, 'i' },
{ "long-options", 0, 0, 0 },
{ "one-per-guest", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "uuid", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
@@ -143,6 +144,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
} else if (STREQ (long_options[option_index].name, "csv")) {
diff --git a/diff/diff.c b/diff/diff.c
index b113f29..8b0fda0 100644
--- a/diff/diff.c
+++ b/diff/diff.c
@@ -167,6 +167,7 @@ main (int argc, char *argv[])
{ "help", 0, 0, HELP_OPTION },
{ "human-readable", 0, 0, 'h' },
{ "keys-from-stdin", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "time", 0, 0, 0 },
{ "times", 0, 0, 0 },
{ "time-days", 0, 0, 0 },
@@ -208,6 +209,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
} else if (STREQ (long_options[option_index].name, "echo-keys")) {
diff --git a/edit/edit.c b/edit/edit.c
index 20b2963..6281a2a 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -117,6 +117,7 @@ main (int argc, char *argv[])
{ "keys-from-stdin", 0, 0, 0 },
{ "long-options", 0, 0, 0 },
{ "mount", 1, 0, 'm' },
+ { "short-options", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
@@ -145,6 +146,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
} else if (STREQ (long_options[option_index].name, "echo-keys")) {
diff --git a/fish/fish.c b/fish/fish.c
index 981a7d4..0432774 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -204,6 +204,7 @@ main (int argc, char *argv[])
{ "ro", 0, 0, 'r' },
{ "rw", 0, 0, 'w' },
{ "selinux", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
@@ -245,6 +246,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "listen"))
remote_control_listen = 1;
else if (STREQ (long_options[option_index].name, "remote")) {
diff --git a/fish/options.c b/fish/options.c
index f7870a4..9ffcc6b 100644
--- a/fish/options.c
+++ b/fish/options.c
@@ -340,6 +340,20 @@ free_mps (struct mp *mp)
free (mp);
}
+/* Implements the internal 'tool --short-options' flag, which just
+ * lists out the short options available. Used by bash completion.
+ */
+void
+display_short_options (const char *format)
+{
+ while (*format) {
+ if (*format != ':')
+ printf ("-%c\n", *format);
+ ++format;
+ }
+ exit (EXIT_SUCCESS);
+}
+
/* Implements the internal 'tool --long-options' flag, which just
* lists out the long options available. Used by bash completion.
*/
@@ -347,7 +361,7 @@ void
display_long_options (const struct option *long_options)
{
while (long_options->name) {
- if (STRNEQ (long_options->name, "long-options"))
+ if (STRNEQ (long_options->name, "long-options") && STRNEQ
(long_options->name, "short-options"))
printf ("--%s\n", long_options->name);
long_options++;
}
diff --git a/fish/options.h b/fish/options.h
index 2c568e6..cf68122 100644
--- a/fish/options.h
+++ b/fish/options.h
@@ -138,6 +138,7 @@ extern char add_drives_handle (guestfs_h *g, struct drv *drv, char
next_drive);
extern void mount_mps (struct mp *mp);
extern void free_drives (struct drv *drv);
extern void free_mps (struct mp *mp);
+extern void display_short_options (const char *) __attribute__((noreturn));
extern void display_long_options (const struct option *) __attribute__((noreturn));
#define OPTION_a \
diff --git a/format/format.c b/format/format.c
index 1651f31..4e6069f 100644
--- a/format/format.c
+++ b/format/format.c
@@ -113,6 +113,7 @@ main (int argc, char *argv[])
{ "long-options", 0, 0, 0 },
{ "lvm", 2, 0, 0 },
{ "partition", 2, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ "wipe", 0, 0, 0 },
@@ -139,6 +140,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "format")) {
OPTION_format;
} else if (STREQ (long_options[option_index].name, "filesystem")) {
diff --git a/fuse/guestmount.c b/fuse/guestmount.c
index 519bba3..f952c47 100644
--- a/fuse/guestmount.c
+++ b/fuse/guestmount.c
@@ -173,6 +173,7 @@ main (int argc, char *argv[])
{ "ro", 0, 0, 'r' },
{ "rw", 0, 0, 'w' },
{ "selinux", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "trace", 0, 0, 'x' },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
@@ -220,6 +221,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "dir-cache-timeout"))
dir_cache_timeout = atoi (optarg);
else if (STREQ (long_options[option_index].name, "fuse-help"))
diff --git a/inspector/inspector.c b/inspector/inspector.c
index 71795ce..5b99efa 100644
--- a/inspector/inspector.c
+++ b/inspector/inspector.c
@@ -111,6 +111,7 @@ main (int argc, char *argv[])
{ "help", 0, 0, HELP_OPTION },
{ "keys-from-stdin", 0, 0, 0 },
{ "long-options", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ "xpath", 1, 0, 0 },
@@ -137,6 +138,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "keys-from-stdin")) {
keys_from_stdin = 1;
} else if (STREQ (long_options[option_index].name, "echo-keys")) {
diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c
index 406aa1d..841c202 100644
--- a/make-fs/make-fs.c
+++ b/make-fs/make-fs.c
@@ -59,6 +59,7 @@ static const struct option long_options[] = {
{ "label", 1, 0, 0 },
{ "long-options", 0, 0, 0 },
{ "partition", 2, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "size", 1, 0, 's' },
{ "type", 1, 0, 't' },
{ "verbose", 0, 0, 'v' },
@@ -125,6 +126,9 @@ main (int argc, char *argv[])
if (STREQ (long_options[option_index].name, "long-options")) {
display_long_options (long_options);
}
+ else if (STREQ (long_options[option_index].name, "short-options")) {
+ display_short_options (options);
+ }
else if (STREQ (long_options[option_index].name, "floppy")) {
size_str = "1440K";
partition = "mbr";
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 83ebd3a..89d8412 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -421,8 +421,15 @@ let skip_dashes str =
let compare_command_line_args a b =
compare (String.lowercase (skip_dashes a)) (String.lowercase (skip_dashes b))
-(* Implements `--long-options'. *)
+(* Implement `--short-options' and `--long-options'. *)
let long_options = ref ([] : (Arg.key * Arg.spec * Arg.doc) list)
+let display_short_options () =
+ List.iter (
+ fun (arg, _, _) ->
+ if string_prefix arg "-" && not (string_prefix arg
"--") then
+ printf "%s\n" arg
+ ) !long_options;
+ exit 0
let display_long_options () =
List.iter (
fun (arg, _, _) ->
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 112648a..bcdeecf 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -92,6 +92,8 @@ val compare_command_line_args : string -> string -> int
(** Compare command line arguments for equality, ignoring any leading [-]s. *)
val long_options : (Arg.key * Arg.spec * Arg.doc) list ref
+val display_short_options : unit -> 'a
+(** Implements [--short-options]. *)
val display_long_options : unit -> 'a
(** Implements [--long-options]. *)
diff --git a/p2v/main.c b/p2v/main.c
index a93ca1c..226f574 100644
--- a/p2v/main.c
+++ b/p2v/main.c
@@ -53,6 +53,7 @@ static const struct option long_options[] = {
{ "help", 0, 0, HELP_OPTION },
{ "cmdline", 1, 0, 0 },
{ "long-options", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
@@ -83,10 +84,21 @@ usage (int status)
/* XXX Copied from fish/options.c. */
static void
+display_short_options (const char *format)
+{
+ while (*format) {
+ if (*format != ':')
+ printf ("-%c\n", *format);
+ ++format;
+ }
+ exit (EXIT_SUCCESS);
+}
+
+static void
display_long_options (const struct option *long_options)
{
while (long_options->name) {
- if (STRNEQ (long_options->name, "long-options"))
+ if (STRNEQ (long_options->name, "long-options") && STRNEQ
(long_options->name, "short-options"))
printf ("--%s\n", long_options->name);
long_options++;
}
@@ -119,6 +131,9 @@ main (int argc, char *argv[])
if (STREQ (long_options[option_index].name, "long-options")) {
display_long_options (long_options);
}
+ else if (STREQ (long_options[option_index].name, "short-options")) {
+ display_short_options (options);
+ }
else if (STREQ (long_options[option_index].name, "cmdline")) {
cmdline = strdup (optarg);
}
diff --git a/rescue/rescue.c b/rescue/rescue.c
index 00187a4..0295634 100644
--- a/rescue/rescue.c
+++ b/rescue/rescue.c
@@ -113,6 +113,7 @@ main (int argc, char *argv[])
{ "rw", 0, 0, 'w' },
{ "scratch", 2, 0, 0 },
{ "selinux", 0, 0, 0 },
+ { "short-options", 0, 0, 0 },
{ "smp", 1, 0, 0 },
{ "suggest", 0, 0, 0 },
{ "verbose", 0, 0, 'v' },
@@ -145,6 +146,8 @@ main (int argc, char *argv[])
case 0: /* options which are long only */
if (STREQ (long_options[option_index].name, "long-options"))
display_long_options (long_options);
+ else if (STREQ (long_options[option_index].name, "short-options"))
+ display_short_options (options);
else if (STREQ (long_options[option_index].name, "selinux")) {
if (guestfs_set_selinux (g, 1) == -1)
exit (EXIT_FAILURE);
diff --git a/resize/resize.ml b/resize/resize.ml
index f54b11f..363e2b6 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -194,6 +194,7 @@ let main () =
"--no-extra-partition", Arg.Clear extra_partition, " " ^
s_"Don't create extra partition";
"--format", Arg.Set_string format, s_"format" ^ "
" ^ s_"Format of input disk";
"--ignore", Arg.String (add ignores), s_"part" ^ "
" ^ s_"Ignore partition";
+ "--short-options", Arg.Unit display_short_options, " " ^
s_"List short options";
"--long-options", Arg.Unit display_long_options, " " ^
s_"List long options";
"--lv-expand", Arg.String (add lv_expands), s_"lv" ^ "
" ^ s_"Expand logical volume";
"--LV-expand", Arg.String (add lv_expands), s_"lv" ^ ditto;
diff --git a/sparsify/cmdline.ml b/sparsify/cmdline.ml
index ec58dc1..88bab72 100644
--- a/sparsify/cmdline.ml
+++ b/sparsify/cmdline.ml
@@ -73,6 +73,7 @@ let parse_cmdline () =
"--ignore", Arg.String (add ignores), s_"fs" ^ " " ^
s_"Ignore filesystem";
"--in-place", Arg.Set in_place, " " ^ s_"Modify the
disk image in-place";
"--inplace", Arg.Set in_place, ditto;
+ "--short-options", Arg.Unit display_short_options, " " ^
s_"List short options";
"--long-options", Arg.Unit display_long_options, " " ^
s_"List long options";
"--machine-readable", Arg.Set machine_readable, " " ^
s_"Make output machine readable";
"-o", Arg.Set_string option, s_"option" ^ "
" ^ s_"Add qemu-img options";
diff --git a/sysprep/main.ml b/sysprep/main.ml
index 057f4cb..1fe3725 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -138,6 +138,7 @@ let main () =
"--enable", Arg.String set_enable, s_"operations" ^ "
" ^ s_"Enable specific operations";
"--format", Arg.String set_format, s_"format" ^ "
" ^ s_"Set format (default: auto)";
"--list-operations", Arg.Unit list_operations, " " ^
s_"List supported operations";
+ "--short-options", Arg.Unit display_short_options, " " ^
s_"List short options";
"--long-options", Arg.Unit display_long_options, " " ^
s_"List long options";
"--mount-options", Arg.Set_string mount_opts, s_"opts" ^ "
" ^ s_"Set mount options (eg /:noatime;/var:rw,noatime)";
"--no-selinux-relabel", Arg.Unit (fun () -> ()),
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index 69a627f..85757e6 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -154,6 +154,7 @@ let parse_cmdline () =
"-ic", Arg.Set_string input_conn, "uri " ^ s_"Libvirt
URI";
"-if", Arg.Set_string input_format,
"format " ^ s_"Input format (for -i disk)";
+ "--short-options", Arg.Unit display_short_options, " " ^
s_"List short options";
"--long-options", Arg.Unit display_long_options, " " ^
s_"List long options";
"--machine-readable", Arg.Set machine_readable, " " ^
s_"Make output machine readable";
"-n", Arg.String add_network, "in:out " ^ s_"Map
network 'in' to 'out'";
--
1.9.3