Separate out the high-level API actions.
[libguestfs.git] / fish / completion.c
1 /* libguestfs generated file
2  * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3  * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
4  *
5  * Copyright (C) 2009 Red Hat Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <config.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #ifdef HAVE_LIBREADLINE
29 #include <readline/readline.h>
30 #endif
31
32 #include "fish.h"
33
34 #ifdef HAVE_LIBREADLINE
35
36 static const char *commands[] = {
37   "add",
38   "add-cdrom",
39   "add-drive",
40   "aug-close",
41   "aug-defnode",
42   "aug-defvar",
43   "aug-get",
44   "aug-init",
45   "aug-insert",
46   "aug-load",
47   "aug-ls",
48   "aug-match",
49   "aug-mv",
50   "aug-rm",
51   "aug-save",
52   "aug-set",
53   "autosync",
54   "blockdev-flushbufs",
55   "blockdev-getbsz",
56   "blockdev-getro",
57   "blockdev-getsize64",
58   "blockdev-getss",
59   "blockdev-getsz",
60   "blockdev-rereadpt",
61   "blockdev-setbsz",
62   "blockdev-setro",
63   "blockdev-setrw",
64   "cat",
65   "cdrom",
66   "chmod",
67   "chown",
68   "command",
69   "command-lines",
70   "config",
71   "exists",
72   "file",
73   "get-autosync",
74   "get-path",
75   "get-state",
76   "get-verbose",
77   "is-busy",
78   "is-config",
79   "is-dir",
80   "is-file",
81   "is-launching",
82   "is-ready",
83   "kill-subprocess",
84   "launch",
85   "list-devices",
86   "list-partitions",
87   "ll",
88   "ls",
89   "lstat",
90   "lvcreate",
91   "lvm-remove-all",
92   "lvs",
93   "lvs-full",
94   "mkdir",
95   "mkdir-p",
96   "mkfs",
97   "mount",
98   "mounts",
99   "path",
100   "pvcreate",
101   "pvs",
102   "pvs-full",
103   "read-lines",
104   "rm",
105   "rm-rf",
106   "rmdir",
107   "run",
108   "set-autosync",
109   "set-path",
110   "set-verbose",
111   "sfdisk",
112   "stat",
113   "statvfs",
114   "sync",
115   "touch",
116   "tune2fs-l",
117   "umount",
118   "umount-all",
119   "unmount",
120   "unmount-all",
121   "verbose",
122   "vgcreate",
123   "vgs",
124   "vgs-full",
125   "write-file",
126   NULL
127 };
128
129 static char *
130 generator (const char *text, int state)
131 {
132   static int index, len;
133   const char *name;
134
135   if (!state) {
136     index = 0;
137     len = strlen (text);
138   }
139
140   while ((name = commands[index]) != NULL) {
141     index++;
142     if (strncasecmp (name, text, len) == 0)
143       return strdup (name);
144   }
145
146   return NULL;
147 }
148
149 #endif /* HAVE_LIBREADLINE */
150
151 char **do_completion (const char *text, int start, int end)
152 {
153   char **matches = NULL;
154
155 #ifdef HAVE_LIBREADLINE
156   if (start == 0)
157     matches = rl_completion_matches (text, generator);
158 #endif
159
160   return matches;
161 }