On Mon, Jul 13, 2026 at 12:14:47 +0200, Radosław Śmigielski via Devel wrote:
> From: Radoslaw Smigielski <[email protected]>
> 
> Add a completer callback for local file paths used as command output,
> where the target file may not exist yet.
> 
> Use it for 'dump', 'save', and 'blockcopy' commands, and fix
> 'screenshot' to use it instead of vshCompletePathLocalExisting.
> 
> Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9
> Signed-off-by: Radoslaw Smigielski <[email protected]>
> ---
>  tools/virsh-domain.c  |  5 ++++-
>  tools/vsh-completer.c | 18 ++++++++++++++++++
>  tools/vsh-completer.h |  5 +++++
>  3 files changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index aa4f2a7a481b..0a383ea40013 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -2629,6 +2629,7 @@ static const vshCmdOptDef opts_blockcopy[] = {
>      {.name = "dest",
>       .type = VSH_OT_STRING,
>       .unwanted_positional = true,
> +     .completer = vshCompletePathLocalCreate,
>       .help = N_("path of the copy to create")
>      },
>      {.name = "bandwidth",
> @@ -4651,6 +4652,7 @@ static const vshCmdOptDef opts_save[] = {
>       .type = VSH_OT_STRING,
>       .positional = true,
>       .required = true,
> +     .completer = vshCompletePathLocalCreate,
>       .help = N_("where to save the data")
>      },
>      {.name = "bypass-cache",
> @@ -5911,6 +5913,7 @@ static const vshCmdOptDef opts_dump[] = {
>       .type = VSH_OT_STRING,
>       .positional = true,
>       .required = true,
> +     .completer = vshCompletePathLocalCreate,
>       .help = N_("where to dump the core")
>      },
>      VIRSH_COMMON_OPT_LIVE(N_("perform a live core dump if supported")),
> @@ -6081,7 +6084,7 @@ static const vshCmdOptDef opts_screenshot[] = {
>      {.name = "file",
>       .type = VSH_OT_STRING,
>       .unwanted_positional = true,
> -     .completer = vshCompletePathLocalExisting,
> +     .completer = vshCompletePathLocalCreate,
>       .help = N_("where to store the screenshot")
>      },
>      {.name = "screen",
> diff --git a/tools/vsh-completer.c b/tools/vsh-completer.c
> index 8f0376879cdb..ba137ebe6c16 100644
> --- a/tools/vsh-completer.c
> +++ b/tools/vsh-completer.c
> @@ -172,6 +172,24 @@ vshCompletePathLocalExisting(vshControl *ctl 
> G_GNUC_UNUSED,
>  }
>  
>  
> +/**
> + * vshCompletePathLocalCreate:
> + *
> + * Complete a path to local file used as output.
> + * The outout file may not exist yet.
> + *
> + * Note: For now this is a no-op. Readline does the correct thing
> + *       and completes local files list.

The second sentence here is misleading because you don't really want to
complete existing files here. I'll drop it.


> + */
> +char **
> +vshCompletePathLocalCreate(vshControl *ctl G_GNUC_UNUSED,
> +                           const vshCmd *cmd G_GNUC_UNUSED,
> +                           unsigned int completerflags G_GNUC_UNUSED)
> +{
> +    return NULL;
> +}
> +
> +
>  /**
>   * vshCompleteEmpty:
>   *
> diff --git a/tools/vsh-completer.h b/tools/vsh-completer.h
> index b479156062c0..5639974c0b86 100644
> --- a/tools/vsh-completer.h
> +++ b/tools/vsh-completer.h
> @@ -35,6 +35,11 @@ vshCompletePathLocalExisting(vshControl *ctl,
>                               const vshCmd *cmd,
>                               unsigned int completerflags);
>  
> +char **
> +vshCompletePathLocalCreate(vshControl *ctl,
> +                           const vshCmd *cmd,
> +                           unsigned int completerflags);
> +
>  char **
>  vshCompleteEmpty(vshControl *ctl,
>                   const vshCmd *cmd,
> -- 
> 2.54.0
> 

Reviewed-by: Peter Krempa <[email protected]>

Reply via email to