vsh: Remove unused infrastructure for command completion

Remove the old helpers which were used previously to pick which field to
complete.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2024-04-15 11:45:14 +02:00
parent da3c5638f9
commit 41efec103d
4 changed files with 8 additions and 24 deletions

View File

@ -770,7 +770,7 @@ virshParseArgv(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], NULL, 0);
return vshCommandStringParse(ctl, argv[optind], NULL);
} else {
return vshCommandArgvParse(ctl, argc - optind, argv + optind);
}
@ -908,7 +908,7 @@ main(int argc, char **argv)
if (*ctl->cmdstr) {
vshReadlineHistoryAdd(ctl->cmdstr);
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL, 0))
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
vshCommandRun(ctl, ctl->cmd);
}
VIR_FREE(ctl->cmdstr);

View File

@ -1331,7 +1331,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], NULL, 0);
return vshCommandStringParse(ctl, argv[optind], NULL);
} else {
return vshCommandArgvParse(ctl, argc - optind, argv + optind);
}
@ -1558,7 +1558,7 @@ main(int argc, char **argv)
if (*ctl->cmdstr) {
vshReadlineHistoryAdd(ctl->cmdstr);
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL, 0))
if (vshCommandStringParse(ctl, ctl->cmdstr, NULL))
vshCommandRun(ctl, ctl->cmd);
}
VIR_FREE(ctl->cmdstr);

View File

@ -1430,7 +1430,6 @@ struct _vshCommandParser {
char **, bool);
/* vshCommandStringGetArg() */
char *pos;
const char *originalLine;
size_t point;
/* vshCommandArgvGetArg() */
char **arg_pos;
@ -1543,9 +1542,6 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
arg->data = g_steal_pointer(&tkdata);
arg->next = NULL;
if (parser->pos - parser->originalLine == parser->point - 1)
arg->completeThis = true;
if (!first)
first = arg;
if (last)
@ -1596,9 +1592,6 @@ vshCommandParse(vshControl *ctl, vshCommandParser *parser, vshCmd **partial)
arg->data = g_steal_pointer(&tkdata);
arg->next = NULL;
if (parser->pos - parser->originalLine == parser->point)
arg->completeThis = true;
if (!first)
first = arg;
if (last)
@ -1812,23 +1805,18 @@ vshCommandStringGetArg(vshControl *ctl, vshCommandParser *parser, char **res,
* @ctl virsh control structure
* @cmdstr: string to parse
* @partial: store partially parsed command here
* @point: position of cursor (rl_point)
*
* Parse given string @cmdstr as a command and store it under
* @ctl->cmd. For readline completion, if @partial is not NULL on
* the input then errors in parsing are ignored (because user is
* still in progress of writing the command string) and partially
* parsed command is stored at *@partial (caller has to free it
* afterwards). Among with @partial, caller must set @point which
* is the position of cursor in @cmdstr (offset, numbered from 1).
* Parser will then set @completeThis attribute to true for the
* vshCmdOpt that appeared under the cursor.
* afterwards).
*/
bool
vshCommandStringParse(vshControl *ctl,
char *cmdstr,
vshCmd **partial,
size_t point)
vshCmd **partial)
{
vshCommandParser parser = { 0 };
@ -1836,8 +1824,6 @@ vshCommandStringParse(vshControl *ctl,
return false;
parser.pos = cmdstr;
parser.originalLine = cmdstr;
parser.point = point;
parser.getNextArg = vshCommandStringGetArg;
return vshCommandParse(ctl, &parser, partial);
}
@ -2844,7 +2830,7 @@ vshReadlineParse(const char *text, int state)
*(line + rl_point) = '\0';
vshCommandStringParse(NULL, line, &partial, rl_point);
vshCommandStringParse(NULL, line, &partial);
if (partial) {
cmd = partial->def;

View File

@ -149,8 +149,6 @@ struct _vshCmdOpt {
char *data; /* allocated data, or NULL for bool option */
const char **argv; /* for VSH_OT_ARGV, the list of options */
char *argvstr; /* space-joined @argv */
bool completeThis; /* true if this is the option user's wishing to
autocomplete */
vshCmdOpt *next;
};
@ -292,7 +290,7 @@ int vshBlockJobOptionBandwidth(vshControl *ctl,
bool vshCommandOptBool(const vshCmd *cmd, const char *name);
bool vshCommandRun(vshControl *ctl, const vshCmd *cmd);
bool vshCommandStringParse(vshControl *ctl, char *cmdstr,
vshCmd **partial, size_t point);
vshCmd **partial);
const char **
vshCommandOptArgv(const vshCmd *cmd,