diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2013-11-14 11:54:18 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-01-22 12:07:17 +0100 |
commit | 4694020d3c0d21f02408d5cc6f44b8fb55b4ee15 (patch) | |
tree | 9e54963e262d2c6f177733db222a34496eb94c49 /qemu-io-cmds.c | |
parent | 0cf17e181798063c3824c8200ba46f25f54faa1a (diff) |
qemu-io: add command completion
Autocomplete qemu-io commands at the interactive prompt.
Note this only completes command names and not their options.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'qemu-io-cmds.c')
-rw-r--r-- | qemu-io-cmds.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 85e4982bd8..6dfb4a51ae 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -94,6 +94,21 @@ static const cmdinfo_t *find_command(const char *cmd) return NULL; } +/* Invoke fn() for commands with a matching prefix */ +void qemuio_complete_command(const char *input, + void (*fn)(const char *cmd, void *opaque), + void *opaque) +{ + cmdinfo_t *ct; + size_t input_len = strlen(input); + + for (ct = cmdtab; ct < &cmdtab[ncmds]; ct++) { + if (strncmp(input, ct->name, input_len) == 0) { + fn(ct->name, opaque); + } + } +} + static char **breakline(char *input, int *count) { int c = 0; |