diff --git a/align/scan.c b/align/scan.c index 0adbfbd03..6598aeb03 100644 --- a/align/scan.c +++ b/align/scan.c @@ -117,6 +117,7 @@ main (int argc, char *argv[]) { "domain", 1, 0, 'd' }, { "format", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, + { "long-options", 0, 0, 0 }, { "quiet", 0, 0, 'q' }, { "uuid", 0, 0, 0, }, { "verbose", 0, 0, 'v' }, @@ -145,7 +146,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "format")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_options); + else if (STREQ (long_options[option_index].name, "format")) { if (!optarg || STREQ (optarg, "")) format = NULL; else diff --git a/cat/virt-cat.c b/cat/virt-cat.c index 91c3d27ac..eec709352 100644 --- a/cat/virt-cat.c +++ b/cat/virt-cat.c @@ -101,6 +101,7 @@ main (int argc, char *argv[]) { "format", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "keys-from-stdin", 0, 0, 0 }, + { "long-options", 0, 0, 0 }, { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { 0, 0, 0, 0 } @@ -126,7 +127,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "keys-from-stdin")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_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")) { echo_keys = 1; diff --git a/cat/virt-filesystems.c b/cat/virt-filesystems.c index 590f429d8..294e84fcd 100644 --- a/cat/virt-filesystems.c +++ b/cat/virt-filesystems.c @@ -156,9 +156,10 @@ main (int argc, char *argv[]) { "help", 0, 0, HELP_OPTION }, { "human-readable", 0, 0, 'h' }, { "keys-from-stdin", 0, 0, 0 }, - { "long", 0, 0, 'l' }, { "logical-volumes", 0, 0, 0 }, { "logvols", 0, 0, 0 }, + { "long", 0, 0, 'l' }, + { "long-options", 0, 0, 0 }, { "lvs", 0, 0, 0 }, { "no-title", 0, 0, 0 }, { "parts", 0, 0, 0 }, @@ -199,7 +200,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "keys-from-stdin")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_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")) { echo_keys = 1; diff --git a/cat/virt-ls.c b/cat/virt-ls.c index b4484e3ca..6386d2fdd 100644 --- a/cat/virt-ls.c +++ b/cat/virt-ls.c @@ -155,6 +155,7 @@ main (int argc, char *argv[]) { "human-readable", 0, 0, 'h' }, { "keys-from-stdin", 0, 0, 0 }, { "long", 0, 0, 'l' }, + { "long-options", 0, 0, 0 }, { "recursive", 0, 0, 'R' }, { "time", 0, 0, 0 }, { "times", 0, 0, 0 }, @@ -191,7 +192,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "keys-from-stdin")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_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")) { echo_keys = 1; diff --git a/df/main.c b/df/main.c index 375da6df2..dbe42d710 100644 --- a/df/main.c +++ b/df/main.c @@ -117,6 +117,7 @@ main (int argc, char *argv[]) { "help", 0, 0, HELP_OPTION }, { "human-readable", 0, 0, 'h' }, { "inodes", 0, 0, 'i' }, + { "long-options", 0, 0, 0 }, { "one-per-guest", 0, 0, 0 }, { "uuid", 0, 0, 0 }, { "verbose", 0, 0, 'v' }, @@ -144,7 +145,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "format")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_options); + else if (STREQ (long_options[option_index].name, "format")) { if (!optarg || STREQ (optarg, "")) format = NULL; else diff --git a/edit/virt-edit.c b/edit/virt-edit.c index 8f988ccdb..60824d15e 100644 --- a/edit/virt-edit.c +++ b/edit/virt-edit.c @@ -122,6 +122,7 @@ main (int argc, char *argv[]) { "format", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "keys-from-stdin", 0, 0, 0 }, + { "long-options", 0, 0, 0 }, { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { 0, 0, 0, 0 } @@ -146,7 +147,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "keys-from-stdin")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_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")) { echo_keys = 1; diff --git a/fish/fish.c b/fish/fish.c index 19e11d4fb..db06734ca 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -191,6 +191,7 @@ main (int argc, char *argv[]) { "keys-from-stdin", 0, 0, 0 }, { "listen", 0, 0, 0 }, { "live", 0, 0, 0 }, + { "long-options", 0, 0, 0 }, { "mount", 1, 0, 'm' }, { "network", 0, 0, 0 }, { "new", 1, 0, 'N' }, @@ -250,7 +251,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "listen")) + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_options); + else if (STREQ (long_options[option_index].name, "listen")) remote_control_listen = 1; else if (STREQ (long_options[option_index].name, "remote")) { if (optarg) { diff --git a/fish/options.c b/fish/options.c index 384ef43e4..f4890db6a 100644 --- a/fish/options.c +++ b/fish/options.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "guestfs.h" @@ -196,3 +197,17 @@ free_mps (struct mp *mp) free (mp); } + +/* Implements the internal 'tool --long-options' flag, which just + * lists out the long options available. Used by bash completion. + */ +void +display_long_options (const struct option *long_options) +{ + while (long_options->name) { + if (STRNEQ (long_options->name, "long-options")) + printf ("--%s\n", long_options->name); + long_options++; + } + exit (EXIT_SUCCESS); +} diff --git a/fish/options.h b/fish/options.h index 41248eb96..e11f78ed4 100644 --- a/fish/options.h +++ b/fish/options.h @@ -19,6 +19,8 @@ #ifndef OPTIONS_H #define OPTIONS_H +#include + #include "guestfs-internal-frontend.h" /* Provided by guestfish or guestmount. */ @@ -100,6 +102,7 @@ extern char add_drives (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_long_options (const struct option *) __attribute__((noreturn)); /* in virt.c */ extern int add_libvirt_drives (const char *guest); diff --git a/format/format.c b/format/format.c index 80750ad1a..8c641f162 100644 --- a/format/format.c +++ b/format/format.c @@ -112,6 +112,7 @@ main (int argc, char *argv[]) { "filesystem", 1, 0, 0 }, { "format", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, + { "long-options", 0, 0, 0 }, { "lvm", 2, 0, 0 }, { "partition", 2, 0, 0 }, { "verbose", 0, 0, 'v' }, @@ -140,7 +141,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "format")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_options); + else if (STREQ (long_options[option_index].name, "format")) { if (!optarg || STREQ (optarg, "")) format = NULL; else diff --git a/fuse/guestmount.c b/fuse/guestmount.c index e11a99a6a..7e283135d 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -161,6 +161,7 @@ main (int argc, char *argv[]) { "inspector", 0, 0, 'i' }, { "keys-from-stdin", 0, 0, 0 }, { "live", 0, 0, 0 }, + { "long-options", 0, 0, 0 }, { "mount", 1, 0, 'm' }, { "no-fork", 0, 0, 0 }, { "no-sync", 0, 0, 'n' }, @@ -216,7 +217,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "dir-cache-timeout")) + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_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")) fuse_help (); diff --git a/inspector/virt-inspector.c b/inspector/virt-inspector.c index d9512ad8a..09a8a13e9 100644 --- a/inspector/virt-inspector.c +++ b/inspector/virt-inspector.c @@ -114,6 +114,7 @@ main (int argc, char *argv[]) { "format", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "keys-from-stdin", 0, 0, 0 }, + { "long-options", 0, 0, 0 }, { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { "xpath", 1, 0, 0 }, @@ -139,7 +140,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "keys-from-stdin")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_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")) { echo_keys = 1; diff --git a/rescue/virt-rescue.c b/rescue/virt-rescue.c index aa343c1b7..aefd3b0de 100644 --- a/rescue/virt-rescue.c +++ b/rescue/virt-rescue.c @@ -110,6 +110,7 @@ main (int argc, char *argv[]) { "domain", 1, 0, 'd' }, { "format", 2, 0, 0 }, { "help", 0, 0, HELP_OPTION }, + { "long-options", 0, 0, 0 }, { "memsize", 1, 0, 'm' }, { "network", 0, 0, 0 }, { "ro", 0, 0, 'r' }, @@ -147,7 +148,9 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "selinux")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_options); + else if (STREQ (long_options[option_index].name, "selinux")) { if (guestfs_set_selinux (g, 1) == -1) exit (EXIT_FAILURE); } else if (STREQ (long_options[option_index].name, "append")) { diff --git a/resize/common_utils.ml b/resize/common_utils.ml index 3e50d19dc..3861c71c5 100644 --- a/resize/common_utils.ml +++ b/resize/common_utils.ml @@ -246,3 +246,13 @@ 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'. *) +let long_options = ref ([] : (Arg.key * Arg.spec * Arg.doc) list) +let display_long_options () = + List.iter ( + fun (arg, _, _) -> + if string_prefix arg "--" && arg <> "--long-options" then + printf "%s\n" arg + ) !long_options; + exit 0 diff --git a/resize/resize.ml b/resize/resize.ml index 70f917fe0..74a5a47e1 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1,5 +1,5 @@ (* virt-resize - * Copyright (C) 2010-2012 Red Hat Inc. + * Copyright (C) 2010-2013 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -91,6 +91,7 @@ let infile, outfile, align_first, alignment, copy_boot_loader, "--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"; + "--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" ^ " -\"-"; "--lvexpand", Arg.String (add lv_expands), s_"lv" ^ " -\"-"; @@ -109,6 +110,7 @@ let infile, outfile, align_first, alignment, copy_boot_loader, "-V", Arg.Unit display_version, " " ^ s_"Display version and exit"; "--version", Arg.Unit display_version, " -\"-"; ] in + long_options := argspec; let disks = ref [] in let anon_fun s = disks := s :: !disks in let usage_msg = diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml index 6ea34ee48..e653deda9 100644 --- a/sparsify/sparsify.ml +++ b/sparsify/sparsify.ml @@ -1,5 +1,5 @@ (* virt-sparsify - * Copyright (C) 2011-2012 Red Hat Inc. + * Copyright (C) 2011-2013 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -62,6 +62,7 @@ let indisk, outdisk, compress, convert, debug_gc, "--debug-gc", Arg.Set debug_gc, " " ^ s_"Debug GC and memory allocations"; "--format", Arg.Set_string format, s_"format" ^ " " ^ s_"Format of input disk"; "--ignore", Arg.String (add ignores), s_"fs" ^ " " ^ s_"Ignore filesystem"; + "--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"; "-q", Arg.Set quiet, " " ^ s_"Quiet output"; @@ -73,6 +74,7 @@ let indisk, outdisk, compress, convert, debug_gc, "-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls"; "--zero", Arg.String (add zeroes), s_"fs" ^ " " ^ s_"Zero filesystem"; ] in + long_options := argspec; let disks = ref [] in let anon_fun s = disks := s :: !disks in let usage_msg = diff --git a/sysprep/main.ml b/sysprep/main.ml index 212538fef..63e410384 100644 --- a/sysprep/main.ml +++ b/sysprep/main.ml @@ -1,5 +1,5 @@ (* virt-sysprep - * Copyright (C) 2012 Red Hat Inc. + * Copyright (C) 2012-2013 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -109,6 +109,7 @@ let debug_gc, operations, g, selinux_relabel, quiet = "--enable", Arg.String set_enable, s_"operations" ^ " " ^ s_"Enable specific operations"; "--format", Arg.Set_string format, s_"format" ^ " " ^ s_"Set format (default: auto)"; "--list-operations", Arg.Unit list_operations, " " ^ s_"List supported operations"; + "--long-options", Arg.Unit display_long_options, " " ^ s_"List long options"; "-q", Arg.Set quiet, " " ^ s_"Don't print log messages"; "--quiet", Arg.Set quiet, " " ^ s_"Don't print log messages"; "--selinux-relabel", Arg.Unit force_selinux_relabel, " " ^ s_"Force SELinux relabel"; @@ -123,6 +124,7 @@ let debug_gc, operations, g, selinux_relabel, quiet = let args = List.sort (fun (a,_,_) (b,_,_) -> compare_command_line_args a b) args in let argspec = Arg.align args in + long_options := argspec; let anon_fun _ = raise (Arg.Bad (s_"extra parameter on the command line")) in let usage_msg = sprintf (f_"\