Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
3a51bff0
Commit
3a51bff0
authored
Aug 04, 2010
by
Pieter Noordhuis
Browse files
Change output format for non-tty redis-cli execution
parent
123a10f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
3a51bff0
...
@@ -61,6 +61,7 @@ static struct config {
...
@@ -61,6 +61,7 @@ static struct config {
int
pubsub_mode
;
int
pubsub_mode
;
int
raw_output
;
/* output mode per command */
int
raw_output
;
/* output mode per command */
int
tty
;
/* flag for default output format */
int
tty
;
/* flag for default output format */
char
mb_sep
;
char
*
auth
;
char
*
auth
;
char
*
historyfile
;
char
*
historyfile
;
}
config
;
}
config
;
...
@@ -108,7 +109,7 @@ static int cliReadSingleLineReply(int fd, int quiet) {
...
@@ -108,7 +109,7 @@ static int cliReadSingleLineReply(int fd, int quiet) {
if
(
reply
==
NULL
)
return
1
;
if
(
reply
==
NULL
)
return
1
;
if
(
!
quiet
)
if
(
!
quiet
)
printf
(
"%s
\n
"
,
reply
);
printf
(
"%s"
,
reply
);
sdsfree
(
reply
);
sdsfree
(
reply
);
return
0
;
return
0
;
}
}
...
@@ -162,7 +163,6 @@ static int cliReadBulkReply(int fd) {
...
@@ -162,7 +163,6 @@ static int cliReadBulkReply(int fd) {
/* If you are producing output for the standard output we want
/* If you are producing output for the standard output we want
* a more interesting output with quoted characters and so forth */
* a more interesting output with quoted characters and so forth */
printStringRepr
(
reply
,
bulklen
);
printStringRepr
(
reply
,
bulklen
);
printf
(
"
\n
"
);
}
}
zfree
(
reply
);
zfree
(
reply
);
return
0
;
return
0
;
...
@@ -183,8 +183,9 @@ static int cliReadMultiBulkReply(int fd) {
...
@@ -183,8 +183,9 @@ static int cliReadMultiBulkReply(int fd) {
printf
(
"(empty list or set)
\n
"
);
printf
(
"(empty list or set)
\n
"
);
}
}
while
(
elements
--
)
{
while
(
elements
--
)
{
printf
(
"%d. "
,
c
);
if
(
config
.
tty
)
printf
(
"%d. "
,
c
);
if
(
cliReadReply
(
fd
))
return
1
;
if
(
cliReadReply
(
fd
))
return
1
;
if
(
elements
)
printf
(
"%c"
,
config
.
mb_sep
);
c
++
;
c
++
;
}
}
return
0
;
return
0
;
...
@@ -199,13 +200,13 @@ static int cliReadReply(int fd) {
...
@@ -199,13 +200,13 @@ static int cliReadReply(int fd) {
}
}
switch
(
type
)
{
switch
(
type
)
{
case
'-'
:
case
'-'
:
printf
(
"(error) "
);
if
(
config
.
tty
)
printf
(
"(error) "
);
cliReadSingleLineReply
(
fd
,
0
);
cliReadSingleLineReply
(
fd
,
0
);
return
1
;
return
1
;
case
'+'
:
case
'+'
:
return
cliReadSingleLineReply
(
fd
,
0
);
return
cliReadSingleLineReply
(
fd
,
0
);
case
':'
:
case
':'
:
printf
(
"(integer) "
);
if
(
config
.
tty
)
printf
(
"(integer) "
);
return
cliReadSingleLineReply
(
fd
,
0
);
return
cliReadSingleLineReply
(
fd
,
0
);
case
'$'
:
case
'$'
:
return
cliReadBulkReply
(
fd
);
return
cliReadBulkReply
(
fd
);
...
@@ -275,7 +276,7 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -275,7 +276,7 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
printf
(
"Reading messages... (press Ctrl-c to quit)
\n
"
);
printf
(
"Reading messages... (press Ctrl-c to quit)
\n
"
);
while
(
1
)
{
while
(
1
)
{
cliReadReply
(
fd
);
cliReadReply
(
fd
);
printf
(
"
\n
"
);
printf
(
"
\n
\n
"
);
}
}
}
}
...
@@ -283,6 +284,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
...
@@ -283,6 +284,9 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
if
(
retval
)
{
if
(
retval
)
{
return
retval
;
return
retval
;
}
}
if
(
!
config
.
raw_output
&&
config
.
tty
)
{
printf
(
"
\n
"
);
}
}
}
return
0
;
return
0
;
}
}
...
@@ -493,6 +497,7 @@ int main(int argc, char **argv) {
...
@@ -493,6 +497,7 @@ int main(int argc, char **argv) {
config
.
auth
=
NULL
;
config
.
auth
=
NULL
;
config
.
historyfile
=
NULL
;
config
.
historyfile
=
NULL
;
config
.
tty
=
1
;
config
.
tty
=
1
;
config
.
mb_sep
=
'\n'
;
if
(
getenv
(
"HOME"
)
!=
NULL
)
{
if
(
getenv
(
"HOME"
)
!=
NULL
)
{
config
.
historyfile
=
malloc
(
256
);
config
.
historyfile
=
malloc
(
256
);
...
@@ -517,7 +522,7 @@ int main(int argc, char **argv) {
...
@@ -517,7 +522,7 @@ int main(int argc, char **argv) {
repl
();
repl
();
}
}
config
.
tty
=
isatty
(
stdout
)
||
(
getenv
(
"FAKETTY"
)
!=
NULL
);
config
.
tty
=
isatty
(
fileno
(
stdout
)
)
||
(
getenv
(
"FAKETTY"
)
!=
NULL
);
argvcopy
=
convertToSds
(
argc
+
1
,
argv
);
argvcopy
=
convertToSds
(
argc
+
1
,
argv
);
if
(
config
.
argn_from_stdin
)
{
if
(
config
.
argn_from_stdin
)
{
sds
lastarg
=
readArgFromStdin
();
sds
lastarg
=
readArgFromStdin
();
...
...
tests/integration/redis-cli.tcl
View file @
3a51bff0
...
@@ -131,4 +131,26 @@ start_server {tags {"cli"}} {
...
@@ -131,4 +131,26 @@ start_server {tags {"cli"}} {
r rpush list bar
r rpush list bar
assert_equal
"1.
\"
foo
\"\n
2.
\"
bar
\"\n
"
[
run_tty_cli lrange list 0 -1
]
assert_equal
"1.
\"
foo
\"\n
2.
\"
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
\t
newline
\n
"
assert_equal
"tab
\t
newline
\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
\n
bar"
[
run_nontty_cli lrange list 0 -1
]
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment