Code

sysdb: Don't pretty-print JSON in non-interactive mode.
[sysdb.git] / src / tools / sysdb / input.c
index 898464af0b550118aa0367337a4e4b85460930c6..2a2d1707101404169febb67d0ac643aaa98ec649 100644 (file)
@@ -160,7 +160,7 @@ input_readline(void)
        }
 
        if (sysdb_input->have_input)
-               prompt = "sysdb-> ";
+               prompt = "     -> ";
        if (sdb_client_eof(sysdb_input->client))
                prompt = "!-> ";
 
@@ -203,12 +203,12 @@ input_readline(void)
                /* some response / error message from the server pending */
                /* XXX: clear current line */
                printf("\n");
-               sdb_command_print_reply(sysdb_input->client);
+               sdb_command_print_reply(sysdb_input);
 
                if (sdb_client_eof(sysdb_input->client)) {
                        rl_callback_handler_remove();
                        /* XXX */
-                       printf("Remote side closed the connection.\n");
+                       sdb_log(SDB_LOG_ERR, "Remote side closed the connection.");
                        /* return EOF -> restart scanner */
                        return 0;
                }
@@ -237,6 +237,24 @@ sdb_input_init(sdb_input_t *input)
        return 0;
 } /* sdb_input_init */
 
+void
+sdb_input_reset(sdb_input_t *input)
+{
+       sdb_input_t reset = SDB_INPUT_INIT;
+
+       if (! input)
+               return;
+
+       if (input->client)
+               sdb_client_destroy(input->client);
+       if (input->user)
+               free(input->user);
+       if (input->input)
+               sdb_strbuf_destroy(input->input);
+
+       *input = reset;
+} /* sdb_input_reset */
+
 int
 sdb_input_mainloop(void)
 {
@@ -307,10 +325,11 @@ sdb_input_reconnect(void)
 {
        sdb_client_close(sysdb_input->client);
        if (sdb_client_connect(sysdb_input->client, sysdb_input->user)) {
-               printf("Failed to reconnect to SysDBd.\n");
+               sdb_log(SDB_LOG_ERR, "Failed to reconnect to SysDBd");
                return -1;
        }
-       printf("Successfully reconnected to SysDBd.\n");
+       sdb_log(SDB_LOG_INFO, "Successfully reconnected to SysDBd");
+       sdb_command_print_server_version(sysdb_input);
        return 0;
 } /* sdb_input_reconnect */