mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
Add --long-options option to most tools.
For example: $ guestfish --long-options --add --cmd-help --connect --csh --domain --echo-keys [etc.] The idea of this is to make it easier to write a bash completion script that accurately expands --<TAB> options for each command.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libintl.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#ifndef OPTIONS_H
|
||||
#define OPTIONS_H
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#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);
|
||||
|
||||
Reference in New Issue
Block a user