summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-05-25 11:28:09 +0100
committerRichard Jones <rjones@redhat.com>2010-05-25 11:31:11 +0100
commitc9f1a45334efca844c8918b9f0de373f16fd9766 (patch)
treec373c8568a8d58cd23478a4f9d86212f3b733b78
parent1bd1f9b85f45275b1600d148530bc1877ff15213 (diff)
downloadlibguestfs-c9f1a45334efca844c8918b9f0de373f16fd9766.tar.gz
libguestfs-c9f1a45334efca844c8918b9f0de373f16fd9766.tar.xz
libguestfs-c9f1a45334efca844c8918b9f0de373f16fd9766.zip
fish: New command: 'supported'
This checks all available optional groups and prints out which ones are supported by the daemon. Note you must launch the appliance first. Example: ><fs> supported augeas yes inotify yes linuxfsuuid yes linuxmodules yes linuxxattrs yes lvm2 yes mknod yes ntfs3g yes ntfsprogs yes realpath yes scrub yes selinux yes xz yes zerofree yes
-rw-r--r--fish/Makefile.am1
-rw-r--r--fish/fish.c14
-rw-r--r--fish/fish.h4
-rw-r--r--fish/guestfish.pod10
-rw-r--r--fish/supported.c81
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/guestfs.pod7
7 files changed, 118 insertions, 0 deletions
diff --git a/fish/Makefile.am b/fish/Makefile.am
index 3dc1a1ea..9166f2dd 100644
--- a/fish/Makefile.am
+++ b/fish/Makefile.am
@@ -49,6 +49,7 @@ guestfish_SOURCES = \
prep.c \
rc.c \
reopen.c \
+ supported.c \
tilde.c \
time.c
diff --git a/fish/fish.c b/fish/fish.c
index d38d1c13..cbbbf970 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -992,6 +992,8 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
r = do_reopen (cmd, argc, argv);
else if (STRCASEEQ (cmd, "sparse"))
r = do_sparse (cmd, argc, argv);
+ else if (STRCASEEQ (cmd, "supported"))
+ r = do_supported (cmd, argc, argv);
else if (STRCASEEQ (cmd, "time"))
r = do_time (cmd, argc, argv);
else
@@ -1049,6 +1051,8 @@ list_builtin_commands (void)
printf ("%-20s %s\n",
"sparse", _("allocate a sparse image file"));
printf ("%-20s %s\n",
+ "supported", _("list supported groups of commands"));
+ printf ("%-20s %s\n",
"time", _("measure time taken to run command"));
/* actions are printed after this (see list_commands) */
@@ -1162,6 +1166,16 @@ display_builtin_command (const char *cmd)
"\n"
" Size can be specified using standard suffixes, eg. '1M'.\n"
));
+ else if (STRCASEEQ (cmd, "supported"))
+ printf (_("supported - list supported groups of commands\n"
+ " supported\n"
+ "\n"
+ " This command returns a list of the optional groups\n"
+ " known to the daemon, and indicates which ones are\n"
+ " supported by this build of the libguestfs appliance.\n"
+ "\n"
+ " See also guestfs(3) section AVAILABILITY.\n"
+ ));
else if (STRCASEEQ (cmd, "time"))
printf (_("time - measure time taken to run command\n"
" time <command> [<args> ...]\n"
diff --git a/fish/fish.h b/fish/fish.h
index a9993b37..b98faf02 100644
--- a/fish/fish.h
+++ b/fish/fish.h
@@ -121,6 +121,9 @@ extern int rc_remote (int pid, const char *cmd, int argc, char *argv[],
/* in reopen.c */
extern int do_reopen (const char *cmd, int argc, char *argv[]);
+/* in supported.c */
+extern int do_supported (const char *cmd, int argc, char *argv[]);
+
/* in time.c */
extern int do_time (const char *cmd, int argc, char *argv[]);
@@ -142,6 +145,7 @@ extern char *try_tilde_expansion (char *path);
"more", "less", \
"reopen", \
"sparse", \
+ "supported", \
"time"
static inline char *
diff --git a/fish/guestfish.pod b/fish/guestfish.pod
index a6d341e4..5e19ac2b 100644
--- a/fish/guestfish.pod
+++ b/fish/guestfish.pod
@@ -785,6 +785,16 @@ For more advanced image creation, see L<qemu-img(1)> utility.
Size can be specified using standard suffixes, eg. C<1M>.
+=head2 supported
+
+ supported
+
+This command returns a list of the optional groups
+known to the daemon, and indicates which ones are
+supported by this build of the libguestfs appliance.
+
+See also L<guestfs(3)/AVAILABILITY>.
+
=head2 time
time command args...
diff --git a/fish/supported.c b/fish/supported.c
new file mode 100644
index 00000000..c97af143
--- /dev/null
+++ b/fish/supported.c
@@ -0,0 +1,81 @@
+/* guestfish - the filesystem interactive shell
+ * Copyright (C) 2010 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "fish.h"
+
+int
+do_supported (const char *cmd, int argc, char *argv[])
+{
+ char **groups;
+
+ /* As a side-effect this also checks that we've called 'launch'. */
+ groups = guestfs_available_all_groups (g);
+ if (groups == NULL)
+ return -1;
+
+ /* Temporarily replace the error handler so that messages don't get
+ * printed to stderr while we are issuing commands.
+ */
+ guestfs_error_handler_cb old_error_cb;
+ void *old_error_cb_data;
+ old_error_cb = guestfs_get_error_handler (g, &old_error_cb_data);
+ guestfs_set_error_handler (g, NULL, NULL);
+
+ /* Work out the max string length of any group name. */
+ size_t i;
+ size_t len = 0;
+ for (i = 0; groups[i] != NULL; ++i) {
+ size_t l = strlen (groups[i]);
+ if (l > len)
+ len = l;
+ }
+
+ for (i = 0; groups[i] != NULL; ++i) {
+ size_t l = strlen (groups[i]);
+ size_t j;
+ for (j = 0; j < len-l; ++j)
+ putchar (' ');
+ printf ("%s", groups[i]);
+ putchar (' ');
+
+ char *gg[] = { groups[i], NULL };
+ int r = guestfs_available (g, gg);
+ if (r == 0)
+ printf ("%s", _("yes"));
+ else
+ printf ("%s", _("no"));
+ putchar ('\n');
+ }
+
+ /* Free groups list. */
+ for (i = 0; groups[i] != NULL; ++i)
+ free (groups[i]);
+ free (groups);
+
+ /* Restore error handler. */
+ guestfs_set_error_handler (g, old_error_cb, old_error_cb_data);
+
+ return 0;
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b233c29d..bb53a76b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -79,6 +79,7 @@ fish/more.c
fish/prep.c
fish/rc.c
fish/reopen.c
+fish/supported.c
fish/tilde.c
fish/time.c
fuse/dircache.c
diff --git a/src/guestfs.pod b/src/guestfs.pod
index 8404e742..e3f6cf05 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -801,6 +801,13 @@ supports the functionality.
@AVAILABILITY@
+=head2 GUESTFISH supported COMMAND
+
+In L<guestfish(3)> there is a handy interactive command
+C<supported> which prints out the available groups and
+whether they are supported by this build of libguestfs.
+Note however that you have to do C<run> first.
+
=head2 SINGLE CALLS AT COMPILE TIME
If you need to test whether a single libguestfs function is