int pubsub_mode;
int raw_output; /* output mode per command */
int tty; /* flag for default output format */
+ char mb_sep;
char *auth;
char *historyfile;
} config;
if (reply == NULL) return 1;
if (!quiet)
- printf("%s\n", reply);
+ printf("%s", reply);
sdsfree(reply);
return 0;
}
/* If you are producing output for the standard output we want
* a more interesting output with quoted characters and so forth */
printStringRepr(reply,bulklen);
- printf("\n");
}
zfree(reply);
return 0;
printf("(empty list or set)\n");
}
while(elements--) {
- printf("%d. ", c);
+ if (config.tty) printf("%d. ", c);
if (cliReadReply(fd)) return 1;
+ if (elements) printf("%c",config.mb_sep);
c++;
}
return 0;
}
switch(type) {
case '-':
- printf("(error) ");
+ if (config.tty) printf("(error) ");
cliReadSingleLineReply(fd,0);
return 1;
case '+':
return cliReadSingleLineReply(fd,0);
case ':':
- printf("(integer) ");
+ if (config.tty) printf("(integer) ");
return cliReadSingleLineReply(fd,0);
case '$':
return cliReadBulkReply(fd);
printf("Reading messages... (press Ctrl-c to quit)\n");
while (1) {
cliReadReply(fd);
- printf("\n");
+ printf("\n\n");
}
}
if (retval) {
return retval;
}
+ if (!config.raw_output && config.tty) {
+ printf("\n");
+ }
}
return 0;
}
config.auth = NULL;
config.historyfile = NULL;
config.tty = 1;
+ config.mb_sep = '\n';
if (getenv("HOME") != NULL) {
config.historyfile = malloc(256);
repl();
}
- config.tty = isatty(stdout) || (getenv("FAKETTY") != NULL);
+ config.tty = isatty(fileno(stdout)) || (getenv("FAKETTY") != NULL);
argvcopy = convertToSds(argc+1, argv);
if (config.argn_from_stdin) {
sds lastarg = readArgFromStdin();
r rpush list bar
assert_equal "1. \"foo\"\n2. \"bar\"\n" [run_tty_cli lrange list 0 -1]
}
+
+ test_nontty_cli "Status reply" {
+ assert_equal "OK" [run_nontty_cli set key bar]
+ assert_equal "bar" [r get key]
+ }
+
+ test_nontty_cli "Integer reply" {
+ r del counter
+ assert_equal "1" [run_nontty_cli incr counter]
+ }
+
+ test_nontty_cli "Bulk reply" {
+ r set key "tab\tnewline\n"
+ assert_equal "tab\tnewline\n" [run_nontty_cli get key]
+ }
+
+ test_nontty_cli "Multi-bulk reply" {
+ r del list
+ r rpush list foo
+ r rpush list bar
+ assert_equal "foo\nbar" [run_nontty_cli lrange list 0 -1]
+ }
}