diff mbox

[3/7] monitor: Add migrate_set_capability completion.

Message ID 1400540600-1328-4-git-send-email-kroosec@gmail.com
State New
Headers show

Commit Message

Hani Benhabiles May 19, 2014, 11:03 p.m. UTC
Signed-off-by: Hani Benhabiles <hani@linux.com>
---
 hmp-commands.hx |  1 +
 hmp.h           |  2 ++
 monitor.c       | 21 +++++++++++++++++++++
 3 files changed, 24 insertions(+)

Comments

Dr. David Alan Gilbert May 21, 2014, 6:42 p.m. UTC | #1
* Hani Benhabiles (kroosec@gmail.com) wrote:
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> ---
>  hmp-commands.hx |  1 +
>  hmp.h           |  2 ++
>  monitor.c       | 21 +++++++++++++++++++++
>  3 files changed, 24 insertions(+)
> 
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 45e1763..919af6e 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -975,6 +975,7 @@ ETEXI
>          .params     = "capability state",
>          .help       = "Enable/Disable the usage of a capability for migration",
>          .mhandler.cmd = hmp_migrate_set_capability,
> +        .command_completion = migrate_set_capability_completion,
>      },
>  
>  STEXI
> diff --git a/hmp.h b/hmp.h
> index a70804d..0c814d0 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -107,5 +107,7 @@ void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
>  void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
>  void watchdog_action_completion(ReadLineState *rs, int nb_args,
>                                  const char *str);
> +void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
> +                                       const char *str);

Thank you for doing this; I spend way too much time typing these commands.

>  #endif
> diff --git a/monitor.c b/monitor.c
> index fb300c2..6a3a5c9 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -4572,6 +4572,27 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
>      add_completion_option(rs, str, "none");
>  }
>  
> +void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
> +                                       const char *str)
> +{
> +    size_t len;
> +
> +    len = strlen(str);
> +    readline_set_completion_index(rs, len);
> +    if (nb_args == 2) {
> +        int i;
> +        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
> +            const char *name = MigrationCapability_lookup[i];
> +            if (!strncmp(str, name, len)) {
> +                readline_add_completion(rs, name);
> +            }
> +        }
> +    } else if (nb_args == 3) {
> +        add_completion_option(rs, str, "on");
> +        add_completion_option(rs, str, "off");
> +    }

It's a shame you have to do all of these manually; if we could tell something
that we had an enum of 'MigrationCapability' then it could remove the command
specific glue.

Dave

> +}
> +
>  static void monitor_find_completion_by_table(Monitor *mon,
>                                               const mon_cmd_t *cmd_table,
>                                               char **args,
> -- 
> 1.8.3.2
> 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Markus Armbruster May 22, 2014, 7:05 a.m. UTC | #2
"Dr. David Alan Gilbert" <dgilbert@redhat.com> writes:

> * Hani Benhabiles (kroosec@gmail.com) wrote:
>> Signed-off-by: Hani Benhabiles <hani@linux.com>
>> ---
>>  hmp-commands.hx |  1 +
>>  hmp.h           |  2 ++
>>  monitor.c       | 21 +++++++++++++++++++++
>>  3 files changed, 24 insertions(+)
>> 
>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>> index 45e1763..919af6e 100644
>> --- a/hmp-commands.hx
>> +++ b/hmp-commands.hx
>> @@ -975,6 +975,7 @@ ETEXI
>>          .params     = "capability state",
>>          .help       = "Enable/Disable the usage of a capability for migration",
>>          .mhandler.cmd = hmp_migrate_set_capability,
>> +        .command_completion = migrate_set_capability_completion,
>>      },
>>  
>>  STEXI
>> diff --git a/hmp.h b/hmp.h
>> index a70804d..0c814d0 100644
>> --- a/hmp.h
>> +++ b/hmp.h
>> @@ -107,5 +107,7 @@ void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
>>  void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
>>  void watchdog_action_completion(ReadLineState *rs, int nb_args,
>>                                  const char *str);
>> +void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
>> +                                       const char *str);
>
> Thank you for doing this; I spend way too much time typing these commands.
>
>>  #endif
>> diff --git a/monitor.c b/monitor.c
>> index fb300c2..6a3a5c9 100644
>> --- a/monitor.c
>> +++ b/monitor.c
>> @@ -4572,6 +4572,27 @@ void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
>>      add_completion_option(rs, str, "none");
>>  }
>>  
>> +void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
>> +                                       const char *str)
>> +{
>> +    size_t len;
>> +
>> +    len = strlen(str);
>> +    readline_set_completion_index(rs, len);
>> +    if (nb_args == 2) {
>> +        int i;
>> +        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
>> +            const char *name = MigrationCapability_lookup[i];
>> +            if (!strncmp(str, name, len)) {
>> +                readline_add_completion(rs, name);
>> +            }
>> +        }
>> +    } else if (nb_args == 3) {
>> +        add_completion_option(rs, str, "on");
>> +        add_completion_option(rs, str, "off");
>> +    }
>
> It's a shame you have to do all of these manually; if we could tell something
> that we had an enum of 'MigrationCapability' then it could remove the command
> specific glue.

HMP command arguments are specified by an args_type string, which can't
express "enumeration", so we use strings instead.

We could hack in another arguments type 'E', abusing the parameter name
like type 'O'.  But I think the args_type string is long past its "best
before" date.

We could replace it by a command schema, like QMP's.  Differences to QMP
include: arguments are positional, fewer types are accepted, and there's
convenience syntax such as size suffixes.

Not exactly an easy task, I'm afraid.

[...]
diff mbox

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 45e1763..919af6e 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -975,6 +975,7 @@  ETEXI
         .params     = "capability state",
         .help       = "Enable/Disable the usage of a capability for migration",
         .mhandler.cmd = hmp_migrate_set_capability,
+        .command_completion = migrate_set_capability_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index a70804d..0c814d0 100644
--- a/hmp.h
+++ b/hmp.h
@@ -107,5 +107,7 @@  void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char *str);
 void ringbuf_read_completion(ReadLineState *rs, int nb_args, const char *str);
 void watchdog_action_completion(ReadLineState *rs, int nb_args,
                                 const char *str);
+void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
+                                       const char *str);
 
 #endif
diff --git a/monitor.c b/monitor.c
index fb300c2..6a3a5c9 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4572,6 +4572,27 @@  void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
     add_completion_option(rs, str, "none");
 }
 
+void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
+                                       const char *str)
+{
+    size_t len;
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    if (nb_args == 2) {
+        int i;
+        for (i = 0; i < MIGRATION_CAPABILITY_MAX; i++) {
+            const char *name = MigrationCapability_lookup[i];
+            if (!strncmp(str, name, len)) {
+                readline_add_completion(rs, name);
+            }
+        }
+    } else if (nb_args == 3) {
+        add_completion_option(rs, str, "on");
+        add_completion_option(rs, str, "off");
+    }
+}
+
 static void monitor_find_completion_by_table(Monitor *mon,
                                              const mon_cmd_t *cmd_table,
                                              char **args,