Skip to content

Commit

Permalink
prompt user to enter valid input for genreating schema from inreach form
Browse files Browse the repository at this point in the history
  • Loading branch information
Jagdish Kunwar committed Mar 16, 2023
1 parent bb23ef0 commit 79a032c
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ public void runCommand(
Boolean shouldAddSchema = options.getAddSchema();
Scanner scanner = new Scanner(System.in);
for (InReachForm form : inReachSettings.getForms()) {
String userResponse = "n";
String userResponse = null;
JSONObject jsonDef = schemaDefinitionFromForm(form);
String schemaId = form.getPrefix().replace("-", "_") + form.getTitle().replace(" ", "_");
if(null == shouldAddSchema) {
// if --generate-schema flag not provided, ask user if they want to create schema or not
System.out.print("Do you want to generate the schema for: " + schemaId + "? (Y/N) [Default: N]: ");
userResponse = scanner.nextLine().toLowerCase();
do {
System.out.print("Do you want to generate the schema for: " + schemaId + "? (Y/N) [Default: N]: ");
userResponse = scanner.nextLine().trim().toLowerCase();
if (!userResponse.matches("[yn]|")) {
System.out.println("A valid response must be provided: Y, N or blank to accept default value.");
}
} while (!userResponse.matches("[yn]|"));
}

if(null != shouldAddSchema || userResponse.equals("y")) {
Expand Down

0 comments on commit 79a032c

Please sign in to comment.