]> granicus.if.org Git - ipset/commitdiff
Allow "new" as a commad alias to "create"
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 1 Feb 2011 19:35:33 +0000 (20:35 +0100)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 1 Feb 2011 19:35:33 +0000 (20:35 +0100)
It's too easy to mistype "n" to "new", so just allow it.

src/ui.c

index 176e1b2d77c5b4cb75e5d4b9361a100925f2c614..3601c65b2285175ad986c8b454d86da67ea4eff1 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -23,9 +23,9 @@
 const struct ipset_commands ipset_commands[] = {
        /* Order is important */
 
-       {       /* c[reate], --create, n, -N */
+       {       /* c[reate], --create, n[ew], -N */
                .cmd = IPSET_CMD_CREATE,
-               .name = { "create", "n" },
+               .name = { "create", "new" },
                .has_arg = IPSET_MANDATORY_ARG2,
                .help = "SETNAME TYPENAME [type-specific-options]\n"
                        "        Create a new set",
@@ -143,14 +143,14 @@ ipset_match_cmd(const char *arg, const char * const name[])
 
        if (len > strlen(name[0]) || !len)
                return false;
-       else if (strncmp(arg, name[0], len) == 0)
+       else if (len > 1 &&
+                ((strncmp(arg, name[0], len) == 0) ||
+                 (name[1] != NULL && (strncmp(arg, name[1], len) == 0))))
                return true;
        else if (len != 1)
                return false;
-       else if (name[1] == NULL)
-               return tolower(arg[0]) == name[0][0];
-       else
-               return tolower(arg[0]) == name[1][0];   
+       else return tolower(arg[0]) == name[0][0] ||
+                   (name[1] != NULL && tolower(arg[0]) == name[1][0]); 
 }
 
 const struct ipset_envopts ipset_envopts[] = {