summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/cli-rl.c36
-rw-r--r--cli/src/cli-rpc-ops.c12
-rw-r--r--cli/src/cli.c26
-rw-r--r--cli/src/cli.h9
4 files changed, 73 insertions, 10 deletions
diff --git a/cli/src/cli-rl.c b/cli/src/cli-rl.c
index 9a37a77de..f9bf7c819 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)
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 790330240..9487badb6 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -183,7 +183,11 @@ gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
#endif
- cli_out ("%s", msg);
+ if (!rsp.op_ret)
+ cli_out ("%s", msg);
+ else
+ cli_err ("%s", msg);
+
ret = rsp.op_ret;
out:
@@ -256,7 +260,11 @@ gf_cli3_1_deprobe_cbk (struct rpc_req *req, struct iovec *iov,
goto out;
}
#endif
- cli_out ("%s", msg);
+ if (!rsp.op_ret)
+ cli_out ("%s", msg);
+ else
+ cli_err ("%s", msg);
+
ret = rsp.op_ret;
out:
diff --git a/cli/src/cli.c b/cli/src/cli.c
index 7a490fed2..6a5ecf698 100644
--- a/cli/src/cli.c
+++ b/cli/src/cli.c
@@ -450,11 +450,35 @@ cli_usage_out (const char *usage)
if (!usage || usage[0] == '\0')
return -1;
- cli_out ("Usage: %s", usage);
+ cli_err ("Usage: %s", usage);
return 0;
}
int
+_cli_err (const char *fmt, ...)
+{
+ struct cli_state *state = NULL;
+ va_list ap;
+ int ret = 0;
+
+ state = global_state;
+
+ va_start (ap, fmt);
+
+#ifdef HAVE_READLINE
+ if (state->rl_enabled && !state->rl_processing)
+ return cli_rl_err(state, fmt, ap);
+#endif
+
+ ret = vfprintf (stderr, fmt, ap);
+ fprintf (stderr, "\n");
+ va_end (ap);
+
+ return ret;
+}
+
+
+int
_cli_out (const char *fmt, ...)
{
struct cli_state *state = NULL;
diff --git a/cli/src/cli.h b/cli/src/cli.h
index f0048beae..0b769812c 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -177,10 +177,12 @@ int cli_cmd_process_line (struct cli_state *state, const char *line);
int cli_rl_enable (struct cli_state *state);
int cli_rl_out (struct cli_state *state, const char *fmt, va_list ap);
+int cli_rl_err (struct cli_state *state, const char *fmt, va_list ap);
int cli_usage_out (const char *usage);
int _cli_out (const char *fmt, ...);
+int _cli_err (const char *fmt, ...);
#define cli_out(fmt...) do { \
FMT_WARN (fmt); \
@@ -189,6 +191,13 @@ int _cli_out (const char *fmt, ...);
\
} while (0)
+#define cli_err(fmt...) do { \
+ FMT_WARN (fmt); \
+ \
+ _cli_err(fmt); \
+ \
+ } while (0)
+
int
cli_submit_request (void *req, call_frame_t *frame,
rpc_clnt_prog_t *prog,