Guestfish built-in commands auto-complete (RHBZ#501878).
[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 *const commands[] = {
37   BUILTIN_COMMANDS_FOR_COMPLETION,
38   "launch",
39   "run",
40   "kill-subprocess",
41   "add-drive",
42   "add",
43   "add-cdrom",
44   "cdrom",
45   "config",
46   "set-qemu",
47   "qemu",
48   "get-qemu",
49   "set-path",
50   "path",
51   "get-path",
52   "set-append",
53   "append",
54   "get-append",
55   "set-autosync",
56   "autosync",
57   "get-autosync",
58   "set-verbose",
59   "verbose",
60   "get-verbose",
61   "is-ready",
62   "is-config",
63   "is-launching",
64   "is-busy",
65   "get-state",
66   "mount",
67   "sync",
68   "touch",
69   "cat",
70   "ll",
71   "ls",
72   "list-devices",
73   "list-partitions",
74   "pvs",
75   "vgs",
76   "lvs",
77   "pvs-full",
78   "vgs-full",
79   "lvs-full",
80   "read-lines",
81   "aug-init",
82   "aug-close",
83   "aug-defvar",
84   "aug-defnode",
85   "aug-get",
86   "aug-set",
87   "aug-insert",
88   "aug-rm",
89   "aug-mv",
90   "aug-match",
91   "aug-save",
92   "aug-load",
93   "aug-ls",
94   "rm",
95   "rmdir",
96   "rm-rf",
97   "mkdir",
98   "mkdir-p",
99   "chmod",
100   "chown",
101   "exists",
102   "is-file",
103   "is-dir",
104   "pvcreate",
105   "vgcreate",
106   "lvcreate",
107   "mkfs",
108   "sfdisk",
109   "write-file",
110   "umount",
111   "unmount",
112   "mounts",
113   "umount-all",
114   "unmount-all",
115   "lvm-remove-all",
116   "file",
117   "command",
118   "command-lines",
119   "stat",
120   "lstat",
121   "statvfs",
122   "tune2fs-l",
123   "blockdev-setro",
124   "blockdev-setrw",
125   "blockdev-getro",
126   "blockdev-getss",
127   "blockdev-getbsz",
128   "blockdev-setbsz",
129   "blockdev-getsz",
130   "blockdev-getsize64",
131   "blockdev-flushbufs",
132   "blockdev-rereadpt",
133   "upload",
134   "download",
135   "checksum",
136   "tar-in",
137   "tar-out",
138   "tgz-in",
139   "tgz-out",
140   "mount-ro",
141   "mount-options",
142   "mount-vfs",
143   "debug",
144   "lvremove",
145   "vgremove",
146   "pvremove",
147   "set-e2label",
148   "get-e2label",
149   "set-e2uuid",
150   "get-e2uuid",
151   "fsck",
152   "zero",
153   "grub-install",
154   "cp",
155   "cp-a",
156   "mv",
157   "drop-caches",
158   "dmesg",
159   "ping-daemon",
160   "equal",
161   "strings",
162   "strings-e",
163   "hexdump",
164   "zerofree",
165   "pvresize",
166   "sfdisk-N",
167   "sfdisk-l",
168   "sfdisk-kernel-geometry",
169   "sfdisk-disk-geometry",
170   "vg-activate-all",
171   "vg-activate",
172   "lvresize",
173   "resize2fs",
174   "find",
175   "e2fsck-f",
176   NULL
177 };
178
179 static char *
180 generator (const char *text, int state)
181 {
182   static int index, len;
183   const char *name;
184
185   if (!state) {
186     index = 0;
187     len = strlen (text);
188   }
189
190   while ((name = commands[index]) != NULL) {
191     index++;
192     if (strncasecmp (name, text, len) == 0)
193       return strdup (name);
194   }
195
196   return NULL;
197 }
198
199 #endif /* HAVE_LIBREADLINE */
200
201 char **do_completion (const char *text, int start, int end)
202 {
203   char **matches = NULL;
204
205 #ifdef HAVE_LIBREADLINE
206   if (start == 0)
207     matches = rl_completion_matches (text, generator);
208 #endif
209
210   return matches;
211 }