Received: from eggs.gnu.org ([2001:4830:134:3::10]:34577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUDSE-0008Bu-4z for qemu-devel@nongnu.org; Sun, 30 Mar 2014 06:59:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUDS8-0003VY-29 for qemu-devel@nongnu.org; Sun, 30 Mar 2014 06:59:06 -0400 Received: from mail-ee0-x231.google.com ([2a00:1450:4013:c00::231]:52435) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUDS7-0003VN-Qq for qemu-devel@nongnu.org; Sun, 30 Mar 2014 06:58:59 -0400 Received: by mail-ee0-f49.google.com with SMTP id c41so5640089eek.36 for ; Sun, 30 Mar 2014 03:58:58 -0700 (PDT) From: Hani Benhabiles Date: Sun, 30 Mar 2014 11:58:28 +0100 Message-Id: <1396177119-24955-7-git-send-email-kroosec@gmail.com> In-Reply-To: <1396177119-24955-1-git-send-email-kroosec@gmail.com> References: <1396177119-24955-1-git-send-email-kroosec@gmail.com> Subject: [Qemu-devel] [PATCH v2 06/17] monitor: Add cpu index argument completion. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@amazon.com, lcapitulino@redhat.com, stefanha@redhat.com, imammedo@redhat.com Signed-off-by: Hani Benhabiles --- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index a411d4f..813c0fb 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -690,6 +690,7 @@ ETEXI .params = "index", .help = "set the default CPU", .mhandler.cmd = hmp_cpu, + .command_completion = cpu_completion, }, STEXI diff --git a/hmp.h b/hmp.h index 6de5d1a..8701b16 100644 --- a/hmp.h +++ b/hmp.h @@ -99,5 +99,6 @@ void device_add_completion(ReadLineState *rs, int nb_args, const char *str); void device_del_completion(ReadLineState *rs, int nb_args, const char *str); void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str); void chardev_add_completion(ReadLineState *rs, int nb_args, const char *str); +void cpu_completion(ReadLineState *rs, int nb_args, const char *str); #endif diff --git a/monitor.c b/monitor.c index 27caa74..29d4f37 100644 --- a/monitor.c +++ b/monitor.c @@ -4429,6 +4429,30 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str) qapi_free_ObjectPropertyInfoList(start); } +void cpu_completion(ReadLineState *rs, int nb_args, const char *str) +{ + CpuInfoList *cpu_list, *start; + size_t len; + + if (nb_args != 2) { + return; + } + len = strlen(str); + readline_set_completion_index(rs, len); + + start = cpu_list = qmp_query_cpus(NULL); + while (cpu_list) { + char name[16]; + snprintf(name, sizeof(name), "%" PRId64, cpu_list->value->CPU); + + if (!strncmp(str, name, len)) { + readline_add_completion(rs, name); + } + cpu_list = cpu_list->next; + } + qapi_free_CpuInfoList(start); +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args, -- 1.8.3.2