Skip to content

Commit 7d1802c

Browse files
authored
Merge pull request #88 from dparrish/fix_optional_flag_completion_issue
Fix optional flag completion issue
2 parents 41fbbb4 + 48231a4 commit 7d1802c

3 files changed

Lines changed: 4 additions & 30 deletions

File tree

clitest.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -307,32 +307,8 @@ int side_length_validator(struct cli_def *cli, const char *name, const char *val
307307
return rc;
308308
}
309309

310-
const char *TransparentColors[] = {
311-
"clear",
312-
"transparent",
313-
"see-through",
314-
};
315-
316-
int transparent_completor(struct cli_def *cli, const char *name, const char *word, struct cli_comphelp *comphelp) {
317-
// Attempt to show matches against the following color strings
318-
const char **color;
319-
int rc = CLI_OK;
320-
printf("transparent_completor called with <%s>\n", word);
321-
for (color = TransparentColors; *color && (rc == CLI_OK); color++) {
322-
if (!word || !strncmp(*color, word, strlen(word))) {
323-
rc = cli_add_comphelp_entry(comphelp, *color);
324-
}
325-
}
326-
return rc;
327-
}
328310
int transparent_validator(struct cli_def *cli, const char *name, const char *value) {
329-
const char **color;
330-
int rc = CLI_ERROR;
331-
printf("color_validator called for %s\n", name);
332-
for (color = TransparentColors; *color; color++) {
333-
if (!strcmp(value, *color)) return CLI_OK;
334-
}
335-
return rc;
311+
return strcasecmp("transparent", value) ? CLI_ERROR : CLI_OK;
336312
}
337313

338314
int check1_validator(struct cli_def *cli, UNUSED(const char *name), UNUSED(const char *value)) {
@@ -443,7 +419,7 @@ void run_child(int x) {
443419
"Calculate perimeter of polygon\nhas embedded "
444420
"newline\nand_a_really_long_line_that_is_much_longer_than_80_columns_to_show_that_wrap_case");
445421
o = cli_register_optarg(c, "transparent", CLI_CMD_OPTIONAL_FLAG, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
446-
"Set transparent flag", transparent_completor, transparent_validator, NULL);
422+
"Set transparent flag", NULL, NULL, NULL);
447423
cli_optarg_addhelp(o, "transparent", "(any case)set to transparent");
448424

449425
cli_register_optarg(

libcli.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,7 @@ static void cli_get_optarg_comphelp(struct cli_def *cli, struct cli_optarg *opta
32133213
if (!(anchor_word && !strncmp(anchor_word, optarg->name, strlen(anchor_word)))) {
32143214
delim_start = DELIM_OPT_START;
32153215
delim_end = DELIM_OPT_END;
3216+
get_completions = NULL; // No point, completor of field is the name itself
32163217
}
32173218
} else if (optarg->flags & CLI_CMD_HYPHENATED_OPTION) {
32183219
delim_start = DELIM_OPT_START;

libcli.spec

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ rm -rf $RPM_BUILD_ROOT
7575
- applied fixes for misspellings on LIBCLI version #defines (issue #75) - fix provided on github by belge-sel on 19Sep2021
7676
- Fix for printing (issue #79) where text left in buffer (from call to cli_bufprint for example) is discarded instead of preserved. Code provided on github by JereLeppanen on 27Apr2021
7777

78-
* Tue Nov 29 2022 Rob Sanders <rsanders@forcepointgov.com> 1.10.8
79-
- Fix for issue #82 (OPTIONAL_FLAG tab completion not honoring user provided callback)
80-
8178
* Wed Nov 16 2022 Rob Sanders <rsanders@forcepointgov.com> 1.10.8
8279
- Doxygen headers for libli.c routines - code provided on github by mpzanoosi on 14May2021
8380

@@ -255,7 +252,7 @@ rm -rf $RPM_BUILD_ROOT
255252
- Disable TAB completion during username entry
256253

257254
* Fri May 2 2008 David Parrish <david@dparrish.com> 1.9.2-1
258-
- Add configurable timeout for cl7i_regular() - defaults to 1 second
255+
- Add configurable timeout for cli_regular() - defaults to 1 second
259256
- Add idle timeout support
260257

261258
* Thu Jul 5 2007 Brendan O'Dea <bod@optus.net> 1.9.1-1

0 commit comments

Comments
 (0)