fish: Move display_*_options functions to a separate file.

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.
This commit is contained in:
Richard W.M. Jones
2016-08-25 12:41:58 +01:00
parent 738c3bf4fd
commit c795d50af3
29 changed files with 128 additions and 35 deletions

View File

@@ -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 \

View File

@@ -40,6 +40,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
#include "parallel.h"
#include "domains.h"

View File

@@ -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 \

View File

@@ -32,6 +32,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
#include "windows.h"
/* Currently open libguestfs handle. */

View File

@@ -36,6 +36,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
/* These globals are shared with options.c. */
guestfs_h *g;

View File

@@ -37,6 +37,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
/* Currently open libguestfs handle. */
guestfs_h *g;

View File

@@ -37,6 +37,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
#include "visit.h"
/* Currently open libguestfs handle. */

View File

@@ -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 \

View File

@@ -38,6 +38,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
#include "domains.h"
#include "parallel.h"
#include "virt-df.h"

View File

@@ -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 \

View File

@@ -39,6 +39,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
#include "visit.h"
/* Internal tree structure built for each guest. */

View File

@@ -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 \

View File

@@ -37,6 +37,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
#include "windows.h"
#include "file-edit.h"

View File

@@ -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 \

66
fish/display-options.c Normal file
View File

@@ -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);
}

25
fish/display-options.h Normal file
View File

@@ -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 */

View File

@@ -48,6 +48,7 @@
#include "fish.h"
#include "options.h"
#include "display-options.h"
#include "progress.h"
#include "c-ctype.h"

View File

@@ -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);
}

View File

@@ -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 { \

View File

@@ -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 \

View File

@@ -33,6 +33,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
/* These globals are shared with options.c. */
guestfs_h *g;

View File

@@ -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 \

View File

@@ -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);

View File

@@ -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 \

View File

@@ -39,6 +39,7 @@
#include "guestfs.h"
#include "options.h"
#include "display-options.h"
/* Currently open libguestfs handle. */
guestfs_h *g;

View File

@@ -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 = \

View File

@@ -40,6 +40,7 @@
#include "xstrtol.h"
#include "options.h"
#include "display-options.h"
guestfs_h *g;
const char *libvirt_uri;

View File

@@ -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 \

View File

@@ -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);