From f8ae70cf7c514c14ca3d2b4d82d959b717d257af Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 11 Apr 2013 13:15:20 +0200 Subject: [PATCH] redis-cli: raise error on bad command line switch. Previously redis-cli never tried to raise an error when an unrecognized switch was encountered, as everything after the initial options is to be transmitted to the server. However this is too liberal, as there are no commands starting with "-". So the new behavior is to produce an error if there is an unrecognized switch starting with "-". This should not break past redis-cli usages but should prevent broken options to be silently discarded. As far the first token not starting with "-" is encountered, all the rest is considered to be part of the command, so you cna still use strings starting with "-" as values, like in: redis-cli --port 6380 set foo --my-value --- src/redis-cli.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index b932110c..5914fd2c 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -729,7 +729,15 @@ static int parseOptions(int argc, char **argv) { sdsfree(version); exit(0); } else { - break; + if (argv[i][0] == '-') { + fprintf(stderr, + "Unrecognized option or bad number of args for: '%s'\n", + argv[i]); + exit(1); + } else { + /* Likely the command name, stop here. */ + break; + } } } return i;