@@ -127,16 +127,36 @@ void connectInteractively(@Nonnull CypherShell shell, @Nonnull ConnectionConfig
127127 }
128128 // else need to prompt for username and password
129129 if (connectionConfig .username ().isEmpty ()) {
130- connectionConfig .setUsername (promptForText ("username: " , null ));
130+ connectionConfig .setUsername (promptForNonEmptyText ("username" , null ));
131131 }
132132 if (connectionConfig .password ().isEmpty ()) {
133- connectionConfig .setPassword (promptForText ("password: " , '*' ));
133+ connectionConfig .setPassword (promptForText ("password" , '*' ));
134134 }
135135 // try again
136136 shell .connect (connectionConfig );
137137 }
138138 }
139139
140+ /**
141+ * @param prompt
142+ * to display to the user
143+ * @param mask
144+ * single character to display instead of what the user is typing, use null if text is not secret
145+ * @return the text which was entered
146+ * @throws Exception
147+ * in case of errors
148+ */
149+ @ Nonnull
150+ private String promptForNonEmptyText (@ Nonnull String prompt , @ Nullable Character mask ) throws Exception {
151+ String text = promptForText (prompt , mask );
152+ if (!text .isEmpty ()) {
153+ return text ;
154+ }
155+ out .println (prompt + " cannot be empty" );
156+ out .println ();
157+ return promptForNonEmptyText (prompt , mask );
158+ }
159+
140160 /**
141161 * @param prompt
142162 * to display to the user
@@ -150,7 +170,7 @@ void connectInteractively(@Nonnull CypherShell shell, @Nonnull ConnectionConfig
150170 private String promptForText (@ Nonnull String prompt , @ Nullable Character mask ) throws Exception {
151171 String line ;
152172 ConsoleReader consoleReader = new ConsoleReader (in , out );
153- line = consoleReader .readLine (prompt , mask );
173+ line = consoleReader .readLine (prompt + ": " , mask );
154174 consoleReader .close ();
155175
156176 if (line == null ) {
0 commit comments