vshCommandStringParse: Allow retrieving partial result

In the future, this function is going to be called from
vshReadlineParse() to provide parsed input for completer
callbacks. The idea is to allow the callbacks to provide more
specific data. For instance, for the following input:

  virsh # domifaddr --domain fedora --interface <TAB><TAB>

the --interface completer callback is going to be called. Now, it
is more user friendly if the completer offers only those
interfaces found in 'fedora' domain. But in order to do that it
needs to be able to retrieve partially parsed result.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik
2017-11-06 15:46:50 +01:00
parent 06e1d36f95
commit 2e688d96a4
4 changed files with 82 additions and 39 deletions

View File

@@ -1335,7 +1335,7 @@ vshAdmParseArgv(vshControl *ctl, int argc, char **argv)
ctl->imode = false;
if (argc - optind == 1) {
vshDebug(ctl, VSH_ERR_INFO, "commands: \"%s\"\n", argv[optind]);
return vshCommandStringParse(ctl, argv[optind]);
return vshCommandStringParse(ctl, argv[optind], NULL);
} else {
return vshCommandArgvParse(ctl, argc - optind, argv + optind);
}
@@ -1555,7 +1555,7 @@ main(int argc, char **argv)
#if WITH_READLINE
add_history(ctl->cmdstr);
#endif
if (vshCommandStringParse(ctl, ctl->cmdstr))
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
vshCommandRun(ctl, ctl->cmd);
}
VIR_FREE(ctl->cmdstr);