By moving these two functions out of the common options parsing code,
it means we don't need to depend on all the other machinery of options
parsing, such as the global variables ("verbose"), libconfig, etc.
---
align/Makefile.am | 2 ++
align/scan.c | 1 +
cat/Makefile.am | 2 ++
cat/cat.c | 1 +
cat/filesystems.c | 1 +
cat/log.c | 1 +
cat/ls.c | 1 +
df/Makefile.am | 2 ++
df/main.c | 1 +
diff/Makefile.am | 2 ++
diff/diff.c | 1 +
edit/Makefile.am | 2 ++
edit/edit.c | 1 +
fish/Makefile.am | 2 ++
fish/display-options.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++
fish/display-options.h | 25 +++++++++++++++++++
fish/fish.c | 1 +
fish/options.c | 31 ------------------------
fish/options.h | 3 ---
format/Makefile.am | 2 ++
format/format.c | 1 +
fuse/Makefile.am | 2 ++
fuse/guestmount.c | 1 +
inspector/Makefile.am | 2 ++
inspector/inspector.c | 1 +
make-fs/Makefile.am | 4 ++-
make-fs/make-fs.c | 1 +
rescue/Makefile.am | 2 ++
rescue/rescue.c | 1 +
29 files changed, 128 insertions(+), 35 deletions(-)
create mode 100644 fish/display-options.c
create mode 100644 fish/display-options.h
diff --git a/align/Makefile.am b/align/Makefile.am
index edae4b9..2b4dee4 100644
--- a/align/Makefile.am
+++ b/align/Makefile.am
@@ -37,6 +37,8 @@ SHARED_SOURCE_FILES = \
../df/parallel.c \
../df/parallel.h \
../fish/config.c \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/inspect.c \
../fish/keys.c \
diff --git a/align/scan.c b/align/scan.c
index 9575eda..4171f8c 100644
--- a/align/scan.c
+++ b/align/scan.c
@@ -40,6 +40,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
#include "parallel.h"
#include "domains.h"
diff --git a/cat/Makefile.am b/cat/Makefile.am
index a2ca16f..266e1c5 100644
--- a/cat/Makefile.am
+++ b/cat/Makefile.am
@@ -41,6 +41,8 @@ CLEANFILES = \
bin_PROGRAMS = virt-cat virt-filesystems virt-log virt-ls
SHARED_SOURCE_FILES = \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/inspect.c \
../fish/keys.c \
diff --git a/cat/cat.c b/cat/cat.c
index 9039f7f..9c8d1a9 100644
--- a/cat/cat.c
+++ b/cat/cat.c
@@ -32,6 +32,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
#include "windows.h"
/* Currently open libguestfs handle. */
diff --git a/cat/filesystems.c b/cat/filesystems.c
index ab24f2d..6c8ce01 100644
--- a/cat/filesystems.c
+++ b/cat/filesystems.c
@@ -36,6 +36,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
/* These globals are shared with options.c. */
guestfs_h *g;
diff --git a/cat/log.c b/cat/log.c
index bacd8b6..0968ef5 100644
--- a/cat/log.c
+++ b/cat/log.c
@@ -37,6 +37,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
/* Currently open libguestfs handle. */
guestfs_h *g;
diff --git a/cat/ls.c b/cat/ls.c
index 282996f..8903159 100644
--- a/cat/ls.c
+++ b/cat/ls.c
@@ -37,6 +37,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
#include "visit.h"
/* Currently open libguestfs handle. */
diff --git a/df/Makefile.am b/df/Makefile.am
index 74a0391..cbfb160 100644
--- a/df/Makefile.am
+++ b/df/Makefile.am
@@ -32,6 +32,8 @@ bin_PROGRAMS = virt-df
SHARED_SOURCE_FILES = \
../fish/config.c \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/inspect.c \
../fish/keys.c \
diff --git a/df/main.c b/df/main.c
index f1d874a..3f9296f 100644
--- a/df/main.c
+++ b/df/main.c
@@ -38,6 +38,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
#include "domains.h"
#include "parallel.h"
#include "virt-df.h"
diff --git a/diff/Makefile.am b/diff/Makefile.am
index 9421771..87d18c5 100644
--- a/diff/Makefile.am
+++ b/diff/Makefile.am
@@ -31,6 +31,8 @@ bin_PROGRAMS = virt-diff
SHARED_SOURCE_FILES = \
../cat/visit.h \
../cat/visit.c \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/inspect.c \
../fish/keys.c \
diff --git a/diff/diff.c b/diff/diff.c
index 2ac71eb..e0eea57 100644
--- a/diff/diff.c
+++ b/diff/diff.c
@@ -39,6 +39,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
#include "visit.h"
/* Internal tree structure built for each guest. */
diff --git a/edit/Makefile.am b/edit/Makefile.am
index b4dd8a1..709bfca 100644
--- a/edit/Makefile.am
+++ b/edit/Makefile.am
@@ -30,6 +30,8 @@ bin_PROGRAMS = virt-edit
SHARED_SOURCE_FILES = \
../fish/config.c \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/file-edit.h \
../fish/file-edit.c \
diff --git a/edit/edit.c b/edit/edit.c
index 8a0c00c..6f3e388 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -37,6 +37,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
#include "windows.h"
#include "file-edit.h"
diff --git a/fish/Makefile.am b/fish/Makefile.am
index aa0ef74..1e3c1d9 100644
--- a/fish/Makefile.am
+++ b/fish/Makefile.am
@@ -72,6 +72,8 @@ EXTRA_DIST = \
# files must not include other guestfish files.
SHARED_SOURCE_FILES = \
config.c \
+ display-options.h \
+ display-options.c \
domain.c \
inspect.c \
keys.c \
diff --git a/fish/display-options.c b/fish/display-options.c
new file mode 100644
index 0000000..18f7700
--- /dev/null
+++ b/fish/display-options.c
@@ -0,0 +1,66 @@
+/* libguestfs - implement --short-options and --long-options
+ * Copyright (C) 2010-2016 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/**
+ * This file contains common code used to implement I<--short-options>
+ * and I<--long-options> in C virt tools. (The equivalent for
+ * OCaml virt tools is implemented by F<mllib/getopt.ml>).
+ *
+ * These "hidden" options are used to implement bash tab completion.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+
+#include "guestfs-internal-all.h"
+#include "display-options.h"
+
+/**
+ * Implements the internal C<tool I<--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 C<tool I<--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") &&
+ STRNEQ (long_options->name, "short-options"))
+ printf ("--%s\n", long_options->name);
+ long_options++;
+ }
+ exit (EXIT_SUCCESS);
+}
diff --git a/fish/display-options.h b/fish/display-options.h
new file mode 100644
index 0000000..f295d6d
--- /dev/null
+++ b/fish/display-options.h
@@ -0,0 +1,25 @@
+/* libguestfs - implement --short-options and --long-options
+ * Copyright (C) 2010-2016 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef DISPLAY_OPTIONS_H
+#define DISPLAY_OPTIONS_H
+
+extern void display_short_options (const char *) __attribute__((noreturn));
+extern void display_long_options (const struct option *) __attribute__((noreturn));
+
+#endif /* DISPLAY_OPTIONS_H */
diff --git a/fish/fish.c b/fish/fish.c
index 302b52f..f20fbc0 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -48,6 +48,7 @@
#include "fish.h"
#include "options.h"
+#include "display-options.h"
#include "progress.h"
#include "c-ctype.h"
diff --git a/fish/options.c b/fish/options.c
index 653be24..96db212 100644
--- a/fish/options.c
+++ b/fish/options.c
@@ -367,34 +367,3 @@ free_mps (struct mp *mp)
free (mp);
}
-
-/**
- * Implements the internal C<tool I<--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 C<tool I<--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") &&
- STRNEQ (long_options->name, "short-options"))
- printf ("--%s\n", long_options->name);
- long_options++;
- }
- exit (EXIT_SUCCESS);
-}
diff --git a/fish/options.h b/fish/options.h
index bbe38aa..89afe9e 100644
--- a/fish/options.h
+++ b/fish/options.h
@@ -22,7 +22,6 @@
#include <config.h>
#include <stdbool.h>
-#include <getopt.h>
#include "guestfs-internal-frontend.h"
@@ -140,8 +139,6 @@ 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 \
do { \
diff --git a/format/Makefile.am b/format/Makefile.am
index 9951ba1..d955e35 100644
--- a/format/Makefile.am
+++ b/format/Makefile.am
@@ -30,6 +30,8 @@ bin_PROGRAMS = virt-format
SHARED_SOURCE_FILES = \
../fish/config.c \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/inspect.c \
../fish/keys.c \
diff --git a/format/format.c b/format/format.c
index 5933aeb..0ce4ac4 100644
--- a/format/format.c
+++ b/format/format.c
@@ -33,6 +33,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
/* These globals are shared with options.c. */
guestfs_h *g;
diff --git a/fuse/Makefile.am b/fuse/Makefile.am
index da0e636..c70f649 100644
--- a/fuse/Makefile.am
+++ b/fuse/Makefile.am
@@ -40,6 +40,8 @@ bin_PROGRAMS = \
# between guestfish and guestmount.
SHARED_SOURCE_FILES = \
../fish/config.c \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/inspect.c \
../fish/keys.c \
diff --git a/fuse/guestmount.c b/fuse/guestmount.c
index dccc7ba..9da96d2 100644
--- a/fuse/guestmount.c
+++ b/fuse/guestmount.c
@@ -41,6 +41,7 @@
#include "ignore-value.h"
#include "options.h"
+#include "display-options.h"
static int write_pipe_fd (int fd);
static int write_pid_file (const char *pid_file, pid_t pid);
diff --git a/inspector/Makefile.am b/inspector/Makefile.am
index cdaedf3..af596bf 100644
--- a/inspector/Makefile.am
+++ b/inspector/Makefile.am
@@ -58,6 +58,8 @@ bin_PROGRAMS = virt-inspector
SHARED_SOURCE_FILES = \
../fish/config.c \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/inspect.c \
../fish/keys.c \
diff --git a/inspector/inspector.c b/inspector/inspector.c
index 4c027df..9a8fa4d 100644
--- a/inspector/inspector.c
+++ b/inspector/inspector.c
@@ -39,6 +39,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
/* Currently open libguestfs handle. */
guestfs_h *g;
diff --git a/make-fs/Makefile.am b/make-fs/Makefile.am
index 2bec12f..ea723af 100644
--- a/make-fs/Makefile.am
+++ b/make-fs/Makefile.am
@@ -29,9 +29,11 @@ CLEANFILES = \
bin_PROGRAMS = virt-make-fs
SHARED_SOURCE_FILES = \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
+ ../fish/domain.c \
../fish/options.h \
../fish/options.c \
- ../fish/domain.c \
../fish/uri.c
virt_make_fs_SOURCES = \
diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c
index 2f91370..ade2e60 100644
--- a/make-fs/make-fs.c
+++ b/make-fs/make-fs.c
@@ -40,6 +40,7 @@
#include "xstrtol.h"
#include "options.h"
+#include "display-options.h"
guestfs_h *g;
const char *libvirt_uri;
diff --git a/rescue/Makefile.am b/rescue/Makefile.am
index 1568730..58564dc 100644
--- a/rescue/Makefile.am
+++ b/rescue/Makefile.am
@@ -31,6 +31,8 @@ bin_PROGRAMS = virt-rescue
SHARED_SOURCE_FILES = \
../fish/config.c \
+ ../fish/display-options.h \
+ ../fish/display-options.c \
../fish/domain.c \
../fish/inspect.c \
../fish/keys.c \
diff --git a/rescue/rescue.c b/rescue/rescue.c
index 37b82f6..0f83f04 100644
--- a/rescue/rescue.c
+++ b/rescue/rescue.c
@@ -35,6 +35,7 @@
#include "guestfs.h"
#include "options.h"
+#include "display-options.h"
static void add_scratch_disks (int n, struct drv **drvs);
static void do_suggestion (struct drv *drvs);
--
2.7.4