virsh: completer: Introduce dummy completer for local files

For now the completion does the correct thing of completing a local path
if NULL is returned.

Introduce 'virshCompletePathLocalExisting' and use it in the
'VIRSH_COMMON_OPT_FILE' macro.

This for now serves as an annotation for the function which want to read
a file on the host running virsh. In the future this can be used with a
more sophisticated implementation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-09-15 17:08:37 +02:00
parent bc4739ed77
commit 16252b16b7
3 changed files with 23 additions and 0 deletions

View File

@ -128,3 +128,20 @@ virshCommaStringListComplete(const char *input,
return g_steal_pointer(&ret);
}
/**
* virshCompletePathLocalExisting:
*
* Complete a path to a existing file used as input. The file is used as input
* for virsh so only local files are considered.
*
* Note: For now this is a no-op. Readline does the correct thing.
*/
char **
virshCompletePathLocalExisting(vshControl *ctl G_GNUC_UNUSED,
const vshCmd *cmd G_GNUC_UNUSED,
unsigned int completerflags G_GNUC_UNUSED)
{
return NULL;
}

View File

@ -35,3 +35,8 @@
char **
virshCommaStringListComplete(const char *input,
const char **options);
char **
virshCompletePathLocalExisting(vshControl *ctl,
const vshCmd *cmd,
unsigned int completerflags);

View File

@ -100,6 +100,7 @@
{.name = "file", \
.type = VSH_OT_DATA, \
.flags = VSH_OFLAG_REQ, \
.completer = virshCompletePathLocalExisting, \
.help = _helpstr \
}