mirror of
https://git.openafs.org/openafs.git
synced 2025-01-31 05:27:44 +00:00
cmd: Add support for disabling specific abbrevs
Sometimes, when adding a new command parameter, it's necessary to prevent it from colliding with an existing abbreviation. This patch adds a new command flag CMD_NOABBRV which can be set on a parameter to indicate that it should not be considered when checking for ambiguous abbreviations. For example, if a command has the existing '-cell' option which is popularly abbreviated to '-c', adding a '-config' option would cause the existing abbreviation to stop working. However, if '-config' is added with the NOABBRV flag set, '-c' will continue to work. Change-Id: I3b6d718f9dd81c44fb1d10c904db6a4a0fd763b8 Reviewed-on: http://gerrit.openafs.org/4810 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Jeffrey Altman <jaltman@openafs.org> Reviewed-by: Derrick Brashear <shadow@dementia.org>
This commit is contained in:
parent
c47f81d707
commit
78c0e3b0ef
@ -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) {
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user