Generate a dummy 'Fedora' fedora.img in images directory for use by tests.
[libguestfs.git] / fish / supported.c
1 /* guestfish - the filesystem interactive shell
2  * Copyright (C) 2010 Red Hat Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <config.h>
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include "fish.h"
27
28 int
29 run_supported (const char *cmd, size_t argc, char *argv[])
30 {
31   char **groups;
32
33   /* As a side-effect this also checks that we've called 'launch'. */
34   groups = guestfs_available_all_groups (g);
35   if (groups == NULL)
36     return -1;
37
38   /* Temporarily replace the error handler so that messages don't get
39    * printed to stderr while we are issuing commands.
40    */
41   guestfs_error_handler_cb old_error_cb;
42   void *old_error_cb_data;
43   old_error_cb = guestfs_get_error_handler (g, &old_error_cb_data);
44   guestfs_set_error_handler (g, NULL, NULL);
45
46   /* Work out the max string length of any group name. */
47   size_t i;
48   size_t len = 0;
49   for (i = 0; groups[i] != NULL; ++i) {
50     size_t l = strlen (groups[i]);
51     if (l > len)
52       len = l;
53   }
54
55   for (i = 0; groups[i] != NULL; ++i) {
56     size_t l = strlen (groups[i]);
57     size_t j;
58     for (j = 0; j < len-l; ++j)
59       putchar (' ');
60     printf ("%s", groups[i]);
61     putchar (' ');
62
63     char *gg[] = { groups[i], NULL };
64     int r = guestfs_available (g, gg);
65     if (r == 0)
66       printf ("%s", _("yes"));
67     else
68       printf ("%s", _("no"));
69     putchar ('\n');
70   }
71
72   /* Free groups list. */
73   for (i = 0; groups[i] != NULL; ++i)
74     free (groups[i]);
75   free (groups);
76
77   /* Restore error handler. */
78   guestfs_set_error_handler (g, old_error_cb, old_error_cb_data);
79
80   return 0;
81 }