Revert marking password as required in JOpt parser

This is a partial reversion of the earlier commit. Marking the password
option as required at the parser level made it impossible to run
./bisq-cli without options or arguments and get the help text. This is a
useful thing to do, and not worth creating a bad user experience to get
the free required option error handling and error messaging.
This commit is contained in:
Chris Beams 2020-04-26 21:44:03 +02:00
parent a6a8702084
commit 312ef30b70
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
2 changed files with 26 additions and 7 deletions

View File

@ -75,8 +75,7 @@ public class CliMain {
.defaultsTo(9998);
var passwordOpt = parser.accepts("password", "rpc server password")
.withRequiredArg()
.required();
.withRequiredArg();
OptionSet options = null;
try {
@ -111,6 +110,10 @@ public class CliMain {
var host = options.valueOf(hostOpt);
var port = options.valueOf(portOpt);
var password = options.valueOf(passwordOpt);
if (password == null) {
err.println("Error: missing required 'password' option");
exit(EXIT_FAILURE);
}
var credentials = new PasswordCallCredentials(password);

View File

@ -52,8 +52,8 @@ echo "========================================================================"
OUTPUT=$(expect -c '
# exp_internal 1
puts "TEST missing required password option error"
set expected "Error: Missing required option(s) \\\[password\\\]"
spawn ./bisq-cli anymethod
set expected "Error: missing required '\''password'\'' option"
spawn ./bisq-cli getversion
expect {
$expected { puts "PASS" }
default {
@ -133,8 +133,24 @@ OUTPUT=$(expect -c '
}
')
echo "$OUTPUT"
echo "========================================================================"
echo "TEST help (todo)"
./bisq-cli --password=xyz --help
OUTPUT=$(expect -c '
puts "TEST running with no options or arguments prints help text"
# exp_internal 1
set expected "Bisq RPC Client"
spawn ./bisq-cli
expect {
$expected { puts "PASS" }
default {
set results $expect_out(buffer)
puts "FAIL expected = $expected"
puts " actual = $results"
}
}
')
echo "$OUTPUT"
echo "========================================================================"
echo "TEST --help option prints help text"
./bisq-cli --help