mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-05 13:30:28 +01:00
cli: add arbitrary string list completion helper
This commit is contained in:
parent
39f6d5a5ba
commit
e2fe0eeb18
2 changed files with 24 additions and 0 deletions
|
|
@ -1442,3 +1442,25 @@ nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, char
|
|||
|
||||
return nmc->return_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* nmc_complete_strings:
|
||||
* @prefix: a string to match
|
||||
* @...: a %NULL-terminated list of candidate strings
|
||||
*
|
||||
* Prints all the matching candidates for completion. Useful when there's
|
||||
* no better way to suggest completion other than a hardcoded string list.
|
||||
*/
|
||||
void
|
||||
nmc_complete_strings (const char *prefix, ...)
|
||||
{
|
||||
va_list args;
|
||||
const char *candidate;
|
||||
|
||||
va_start (args, prefix);
|
||||
while ((candidate = va_arg (args, const char *))) {
|
||||
if (!*prefix || matches (prefix, candidate) == 0)
|
||||
g_print ("%s\n", candidate);
|
||||
}
|
||||
va_end (args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,4 +81,6 @@ typedef struct {
|
|||
|
||||
NMCResultCode nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *argv0, int argc, char **argv);
|
||||
|
||||
void nmc_complete_strings (const char *prefix, ...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
#endif /* NMC_COMMON_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue