[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 17/93] qemu-io: add command completion
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 17/93] qemu-io: add command completion |
Date: |
Fri, 24 Jan 2014 18:21:00 +0100 |
From: Stefan Hajnoczi <address@hidden>
Autocomplete qemu-io commands at the interactive prompt.
Note this only completes command names and not their options.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/qemu-io.h | 3 +++
qemu-io-cmds.c | 15 +++++++++++++++
qemu-io.c | 8 +++++++-
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/include/qemu-io.h b/include/qemu-io.h
index a418b46..7e7c07c 100644
--- a/include/qemu-io.h
+++ b/include/qemu-io.h
@@ -42,5 +42,8 @@ bool qemuio_command(BlockDriverState *bs, const char *cmd);
void qemuio_add_command(const cmdinfo_t *ci);
int qemuio_command_usage(const cmdinfo_t *ci);
+void qemuio_complete_command(const char *input,
+ void (*fn)(const char *cmd, void *opaque),
+ void *opaque);
#endif /* QEMU_IO_H */
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 85e4982..6dfb4a5 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;
diff --git a/qemu-io.c b/qemu-io.c
index d7c26d3..fdc46a9 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -236,9 +236,15 @@ static void readline_func(void *opaque, const char *str,
void *readline_opaque)
*line = g_strdup(str);
}
+static void completion_match(const char *cmd, void *opaque)
+{
+ readline_add_completion(readline_state, cmd);
+}
+
static void readline_completion_func(void *opaque, const char *str)
{
- /* No command or argument completion implemented yet */
+ readline_set_completion_index(readline_state, strlen(str));
+ qemuio_complete_command(str, completion_match, NULL);
}
static char *fetchline_readline(void)
--
1.8.1.4
- [Qemu-devel] [PULL 06/93] gluster: Convert aio routines into coroutines, (continued)
- [Qemu-devel] [PULL 06/93] gluster: Convert aio routines into coroutines, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 09/93] sheepdog: fix clone operation by 'qemu-img create -b', Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 07/93] gluster: Implement .bdrv_co_write_zeroes for gluster, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 10/93] qtest: Fix the bug about disable vnc causes "make check" fail, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 11/93] docs: qcow2 compat=1.1 is now the default, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 12/93] vmdk: Fix big flat extent IO, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 13/93] readline: decouple readline from the monitor, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 14/93] readline: move readline to a generic location, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 15/93] osdep: add qemu_set_tty_echo(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 16/93] qemu-io: use readline.c, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 17/93] qemu-io: add command completion,
Kevin Wolf <=
- [Qemu-devel] [PULL 18/93] blkdebug: Use errp for read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 19/93] blkdebug: Don't require sophisticated filename, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 20/93] qdict: Add qdict_array_split(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 21/93] qapi: extend qdict_flatten() for QLists, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 22/93] qemu-option: Add qemu_config_parse_qdict(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 23/93] blkdebug: Always call read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 24/93] blkdebug: Use command-line in read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 25/93] block: Allow reference for bdrv_file_open(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 26/93] block: Pass reference to bdrv_file_open(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 27/93] block: Allow block devices without files, Kevin Wolf, 2014/01/24