diff options
author | Amar Tumballi <amarts@redhat.com> | 2012-04-23 11:11:43 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2012-04-25 00:45:51 -0700 |
commit | 3f35280a364bd35293d3e5804eb2a659a7f174b1 (patch) | |
tree | e400432d3460aaacbdc4e6675978bd1c2c94e4ef /cli/src/cli-rl.c | |
parent | 90d5d569b5a2333094ba8741bb29fe040b695b23 (diff) |
cli: implement a fn 'cli_err()' to send error messages to 'stderr'
we were using 'cli_out()' to send all the possible msgs, which is not
very friendly with scripts, because if one want to get only valid
output with "<command> 2>/error.log 1>/proper-info.log"
Change-Id: I008ebcbd90935c41dbfc1bd2adeb094ed21116cb
Signed-off-by: Amar Tumballi <amarts@redhat.com>
BUG: 815194
Reviewed-on: http://review.gluster.com/3208
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Kaushal M <kaushal@redhat.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'cli/src/cli-rl.c')
-rw-r--r-- | cli/src/cli-rl.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/cli/src/cli-rl.c b/cli/src/cli-rl.c index 9a37a77de5e..f9bf7c81923 100644 --- a/cli/src/cli-rl.c +++ b/cli/src/cli-rl.c @@ -48,7 +48,6 @@ cli_rl_out (struct cli_state *state, const char *fmt, va_list ap) { int tmp_rl_point = rl_point; int n = rl_end; - int i = 0; int ret = 0; if (rl_end >= 0 ) { @@ -56,12 +55,7 @@ cli_rl_out (struct cli_state *state, const char *fmt, va_list ap) rl_redisplay (); } - printf ("\r"); - - for (i = 0; i <= strlen (state->prompt); i++) - printf (" "); - - printf ("\r"); + printf ("\r%*s\r", (int)strlen (state->prompt), ""); ret = vprintf (fmt, ap); @@ -77,6 +71,34 @@ cli_rl_out (struct cli_state *state, const char *fmt, va_list ap) return ret; } +int +cli_rl_err (struct cli_state *state, const char *fmt, va_list ap) +{ + int tmp_rl_point = rl_point; + int n = rl_end; + int ret = 0; + + if (rl_end >= 0 ) { + rl_kill_text (0, rl_end); + rl_redisplay (); + } + + fprintf (stderr, "\r%*s\r", (int)strlen (state->prompt), ""); + + ret = vfprintf (stderr, fmt, ap); + + fprintf (stderr, "\n"); + fflush(stderr); + + if (n) { + rl_do_undo (); + rl_point = tmp_rl_point; + rl_reset_line_state (); + } + + return ret; +} + void cli_rl_process_line (char *line) |