diff --git a/src/cmd/cmd.c b/src/cmd/cmd.c index d0e634102c..d67a816a7f 100644 --- a/src/cmd/cmd.c +++ b/src/cmd/cmd.c @@ -101,8 +101,11 @@ FindType(struct cmd_syndesc *as, char *aname) alias = alias->next; } - /* A hidden option must be a full match (no best matches) */ - if (as->parms[i].flags & CMD_HIDE || !enableAbbreviation) + /* A hidden option, or one which cannot be abbreviated, + * must be a full match (no best matches) */ + if (as->parms[i].flags & CMD_HIDE || + as->parms[i].flags & CMD_NOABBRV || + !enableAbbreviation) continue; if (strncmp(as->parms[i].name, aname, cmdlen) == 0) { diff --git a/src/cmd/cmd.p.h b/src/cmd/cmd.p.h index 3193d56deb..d7c58fe174 100644 --- a/src/cmd/cmd.p.h +++ b/src/cmd/cmd.p.h @@ -45,6 +45,7 @@ struct cmd_parmdesc { #define CMD_EXPANDS 2 /* if list, try to eat tokens through eoline, instead of just 1 */ #define CMD_HIDE 4 /* A hidden option */ #define CMD_PROCESSED 8 +#define CMD_NOABBRV 16 /* Abbreviation not supported */ struct cmd_syndesc { struct cmd_syndesc *next; /* next one in system list */ diff --git a/tests/cmd/command-t.c b/tests/cmd/command-t.c index 846a8543dd..2c9fae470e 100644 --- a/tests/cmd/command-t.c +++ b/tests/cmd/command-t.c @@ -38,6 +38,7 @@ #define FLAG_OFF 0 #define FIRST_OFF 1 #define SECOND_OFF 2 +#define SUGAR_OFF 3 #define FOURTH_OFF 4 #define FIFTH_OFF 5 #define PERHAPS_OFF 6 @@ -67,7 +68,7 @@ main(int argc, char **argv) int retval; char *retstring = NULL; - plan(79); + plan(85); initialize_CMD_error_table(); @@ -154,6 +155,19 @@ main(int argc, char **argv) is_int(CMD_UNKNOWNSWITCH, code, "and fail with cmd_Parse too"); cmd_FreeArgv(tv); + /* Check that paramaters with abbreviation disabled don't make things + * ambiguous */ + cmd_AddParmAtOffset(opts, "-sugar", CMD_SINGLE, CMD_OPTIONAL | CMD_NOABBRV, + "sugar with that", SUGAR_OFF); + code = cmd_ParseLine("-fi foo -s bar -flag", tv, &tc, 100); + is_int(0, code, "cmd_ParseLine succeeds"); + code = cmd_Dispatch(tc, tv); + is_int(0, code, "disabling specific abbreviations succeeds"); + code = cmd_Parse(tc, tv, &retopts); + is_int(0, code, "and works with cmd_Parse into the bargain"); + cmd_FreeOptions(&retopts); + cmd_FreeArgv(tv); + /* Disable positional commands */ cmd_DisablePositionalCommands(); code = cmd_ParseLine("foo bar -flag", tv, &tc, 100);