Skip to content

Commit ab1b5f9

Browse files
lePicimichalvasko
authored andcommitted
yanglint REFACTOR of completion callback
1 parent 81c4839 commit ab1b5f9

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

tools/lint/completion.c

+31-31
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,21 @@
3030
#include "compat.h"
3131
#include "linenoise/linenoise.h"
3232

33-
/* This function can be called in user completion callback to fill
34-
* path completion for them. hint parameter is actually the whole path
35-
* and buf is unused, but included to match the completion callback prototype. */
33+
/**
34+
* @brief Fill path completion.
35+
*
36+
* @param[in] hint Path to directory.
37+
* @param[in] lc For adding completions.
38+
*/
3639
static void
37-
path_completion(const char *buf, const char *hint, linenoiseCompletions *lc)
40+
path_completion(const char *hint, linenoiseCompletions *lc)
3841
{
3942
const char *ptr;
4043
char *full_path, *hint_ptr, match[FILENAME_MAX + 2];
4144
DIR *dir;
4245
struct dirent *ent;
4346
struct stat st;
4447

45-
(void)buf;
46-
4748
lc->path = 1;
4849

4950
ptr = strrchr(hint, '/');
@@ -495,29 +496,28 @@ complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc)
495496
struct autocomplete {
496497
enum COMMAND_INDEX ci; /**< command index to global variable 'commands' */
497498
const char *opt; /**< optional option */
498-
void (*ln_cb)(const char *, const char *, linenoiseCompletions *); /**< linenoise callback to call */
499-
void (*yl_cb)(const char *, char ***, unsigned int *); /**< yanglint callback to call */
499+
void (*yl_cb)(const char *, char ***, unsigned int *); /**< yanglint callback to call */
500500
} ac[] = {
501-
{CMD_ADD, NULL, path_completion, NULL},
502-
{CMD_PRINT, "-f", NULL, get_print_format_arg},
503-
{CMD_PRINT, "-P", NULL, get_schema_completion},
504-
{CMD_PRINT, "-o", path_completion, NULL},
505-
{CMD_PRINT, NULL, NULL, get_model_completion},
506-
{CMD_SEARCHPATH, NULL, path_completion, NULL},
507-
{CMD_EXTDATA, NULL, path_completion, NULL},
508-
{CMD_CLEAR, "-Y", path_completion, NULL},
509-
{CMD_DATA, "-t", NULL, get_data_type_arg},
510-
{CMD_DATA, "-O", path_completion, NULL},
511-
{CMD_DATA, "-R", path_completion, NULL},
512-
{CMD_DATA, "-f", NULL, get_data_in_format_arg},
513-
{CMD_DATA, "-F", NULL, get_data_in_format_arg},
514-
{CMD_DATA, "-d", NULL, get_data_default_arg},
515-
{CMD_DATA, "-o", path_completion, NULL},
516-
{CMD_DATA, NULL, path_completion, NULL},
517-
{CMD_LIST, NULL, NULL, get_list_format_arg},
518-
{CMD_FEATURE, NULL, NULL, get_model_completion},
519-
{CMD_VERB, NULL, NULL, get_verb_arg},
520-
{CMD_DEBUG, NULL, NULL, get_debug_arg},
501+
{CMD_ADD, NULL, NULL},
502+
{CMD_PRINT, "-f", get_print_format_arg},
503+
{CMD_PRINT, "-P", get_schema_completion},
504+
{CMD_PRINT, "-o", NULL},
505+
{CMD_PRINT, NULL, get_model_completion},
506+
{CMD_SEARCHPATH, NULL, NULL},
507+
{CMD_EXTDATA, NULL, NULL},
508+
{CMD_CLEAR, "-Y", NULL},
509+
{CMD_DATA, "-t", get_data_type_arg},
510+
{CMD_DATA, "-O", NULL},
511+
{CMD_DATA, "-R", NULL},
512+
{CMD_DATA, "-f", get_data_in_format_arg},
513+
{CMD_DATA, "-F", get_data_in_format_arg},
514+
{CMD_DATA, "-d", get_data_default_arg},
515+
{CMD_DATA, "-o", NULL},
516+
{CMD_DATA, NULL, NULL},
517+
{CMD_LIST, NULL, get_list_format_arg},
518+
{CMD_FEATURE, NULL, get_model_completion},
519+
{CMD_VERB, NULL, get_verb_arg},
520+
{CMD_DEBUG, NULL, get_debug_arg},
521521
};
522522
size_t name_len;
523523
const char *last, *name, *getoptstr;
@@ -555,10 +555,10 @@ complete_cmd(const char *buf, const char *hint, linenoiseCompletions *lc)
555555
}
556556

557557
/* callback */
558-
if (ac[i].ln_cb) {
559-
ac[i].ln_cb(buf, hint, lc);
560-
} else {
558+
if (ac[i].yl_cb) {
561559
ac[i].yl_cb(hint, &matches, &match_count);
560+
} else {
561+
path_completion(hint, lc);
562562
}
563563
break;
564564
}

0 commit comments

Comments
 (0)