Skip to content

Commit

Permalink
Fix an issue with starting Console without specifying any address
Browse files Browse the repository at this point in the history
When Console is executed without specifying the address (ie., `./typedb console`) it should assume that the user wants to connect to TypeDB.

This behavior was broken in the latest release and this commit attempts to fix that.
  • Loading branch information
lolski committed Jun 7, 2021
1 parent 8aaf996 commit 7ad9b57
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions TypeDBConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,34 +669,36 @@ private CLIOptions() {

@Override
public void run() {
validateAddress();
validateCredential();
validateOptions();
}

private void validateAddress() {
private void validateOptions() {
if (server != null && cluster != null) {
throw new CommandLine.ParameterException(spec.commandLine(), "Either '--server' or '--cluster' must be provided, but not both.");
} else {
if (cluster != null) validateClusterOptions();
else validateServerOptions();
}
}

private void validateCredential() {
if (server != null) {
if (username != null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--username' should only be supplied with '--cluster'");
if (password != null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--password' should only be supplied with '--cluster'");
if (tlsEnabled)
throw new CommandLine.ParameterException(spec.commandLine(), "'--tls-enabled' is only valid with '--cluster'");
if (tlsRootCA != null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--tls-root-ca' is only valid with '--cluster'");
} else {
if (username == null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--username' must be supplied with '--cluster'");
if (password == null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--password' must be supplied with '--cluster'");
if (!tlsEnabled && tlsRootCA != null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--tls-root-ca' should only be supplied when '--tls-enabled' is set to 'true'");
}
private void validateServerOptions() {
if (username != null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--username' should only be supplied with '--cluster'");
if (password != null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--password' should only be supplied with '--cluster'");
if (tlsEnabled)
throw new CommandLine.ParameterException(spec.commandLine(), "'--tls-enabled' is only valid with '--cluster'");
if (tlsRootCA != null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--tls-root-ca' is only valid with '--cluster'");
}

private void validateClusterOptions() {
if (username == null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--username' must be supplied with '--cluster'");
if (password == null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--password' must be supplied with '--cluster'");
if (!tlsEnabled && tlsRootCA != null)
throw new CommandLine.ParameterException(spec.commandLine(), "'--tls-root-ca' should only be supplied when '--tls-enabled' is set to 'true'");
}

@Nullable
Expand Down

0 comments on commit 7ad9b57

Please sign in to comment.