Skip to content

Commit

Permalink
Refactor password reading
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 1, 2024
1 parent 19ecaa7 commit 862a0e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 12 additions & 0 deletions convex-cli/src/main/java/convex/cli/ACommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package convex.cli;

import java.io.Console;
import java.util.Scanner;

import convex.cli.output.Coloured;
Expand Down Expand Up @@ -94,6 +95,17 @@ public String prompt(String string) {
return s;
}
}

public char[] readPassword(String prompt) {
Console c = System.console();
if (c == null) {
throw new CLIError(
"Unable to request password because console is unavaiable. Consider passing a password parameter, or running in interactive mode.");
}

if (isColoured()) prompt = Coloured.blue(prompt);
return c.readPassword(prompt);
}

/**
* Checks if the CLI should output ANSI colours
Expand Down
12 changes: 1 addition & 11 deletions convex-cli/src/main/java/convex/cli/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package convex.cli;

import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
Expand Down Expand Up @@ -334,16 +333,7 @@ public boolean isInteractive() {
return !nonInteractive;
}

public char[] readPassword(String prompt) {
Console c = System.console();
if (c == null) {
throw new CLIError(
"Unable to request password because console is unavaiable. Consider passing a password parameter, or running in interactive mode.");
}

if (!noColour) prompt = Coloured.blue(prompt);
return c.readPassword(prompt);
}


public void informSuccess(String message) {
inform(1, noColour?message:Coloured.green(message));
Expand Down

0 comments on commit 862a0e8

Please sign in to comment.