Improve required-argument opt validation

Make sure non-empty opt values are present in the parsers' custom
validation, or jsimpleopt will throw exceptions with stylistically
inconsisent messages.
This commit is contained in:
ghubstan 2021-03-05 07:10:42 -03:00
parent 62ff79d718
commit d01a7b7fee
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
19 changed files with 35 additions and 29 deletions

View File

@ -38,7 +38,7 @@ public class CancelOfferOptionParser extends AbstractMethodOptionParser implemen
if (options.has(helpOpt))
return this;
if (!options.has(offerIdOpt))
if (!options.has(offerIdOpt) || options.valueOf(offerIdOpt).isEmpty())
throw new IllegalArgumentException("no offer id specified");
return this;

View File

@ -70,22 +70,28 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen
if (options.has(helpOpt))
return this;
if (!options.has(paymentAccountIdOpt))
if (!options.has(paymentAccountIdOpt) || options.valueOf(paymentAccountIdOpt).isEmpty())
throw new IllegalArgumentException("no payment account id specified");
if (!options.has(directionOpt))
if (!options.has(directionOpt) || options.valueOf(directionOpt).isEmpty())
throw new IllegalArgumentException("no direction (buy|sell) specified");
if (!options.has(currencyCodeOpt))
if (!options.has(currencyCodeOpt) || options.valueOf(currencyCodeOpt).isEmpty())
throw new IllegalArgumentException("no currency code specified");
if (!options.has(amountOpt))
if (!options.has(amountOpt) || options.valueOf(amountOpt).isEmpty())
throw new IllegalArgumentException("no btc amount specified");
if (!options.has(mktPriceMarginOpt) && !options.has(fixedPriceOpt))
throw new IllegalArgumentException("no market price margin or fixed price specified");
if (!options.has(securityDepositOpt))
if (options.has(mktPriceMarginOpt) && options.valueOf(mktPriceMarginOpt).isEmpty())
throw new IllegalArgumentException("no market price margin specified");
if (options.has(fixedPriceOpt) && options.valueOf(fixedPriceOpt).isEmpty())
throw new IllegalArgumentException("no fixed price specified");
if (!options.has(securityDepositOpt) || options.valueOf(securityDepositOpt).isEmpty())
throw new IllegalArgumentException("no security deposit specified");
return this;

View File

@ -43,7 +43,7 @@ public class CreatePaymentAcctOptionParser extends AbstractMethodOptionParser im
if (options.has(helpOpt))
return this;
if (!options.has(paymentAcctFormPathOpt))
if (!options.has(paymentAcctFormPathOpt) || options.valueOf(paymentAcctFormPathOpt).isEmpty())
throw new IllegalArgumentException("no path to json payment account form specified");
Path path = Paths.get(options.valueOf(paymentAcctFormPathOpt));

View File

@ -38,7 +38,7 @@ public class GetAddressBalanceOptionParser extends AbstractMethodOptionParser im
if (options.has(helpOpt))
return this;
if (!options.has(addressOpt))
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
throw new IllegalArgumentException("no address specified");
return this;

View File

@ -38,7 +38,7 @@ public class GetBTCMarketPriceOptionParser extends AbstractMethodOptionParser im
if (options.has(helpOpt))
return this;
if (!options.has(currencyCodeOpt))
if (!options.has(currencyCodeOpt) || options.valueOf(currencyCodeOpt).isEmpty())
throw new IllegalArgumentException("no currency code specified");
return this;

View File

@ -38,7 +38,7 @@ public class GetOfferOptionParser extends AbstractMethodOptionParser implements
if (options.has(helpOpt))
return this;
if (!options.has(offerIdOpt))
if (!options.has(offerIdOpt) || options.valueOf(offerIdOpt).isEmpty())
throw new IllegalArgumentException("no offer id specified");
return this;

View File

@ -42,10 +42,10 @@ public class GetOffersOptionParser extends AbstractMethodOptionParser implements
if (options.has(helpOpt))
return this;
if (!options.has(directionOpt))
if (!options.has(directionOpt) || options.valueOf(directionOpt).isEmpty())
throw new IllegalArgumentException("no direction (buy|sell) specified");
if (!options.has(currencyCodeOpt))
if (!options.has(currencyCodeOpt) || options.valueOf(currencyCodeOpt).isEmpty())
throw new IllegalArgumentException("no currency code specified");
return this;

View File

@ -39,7 +39,7 @@ public class GetPaymentAcctFormOptionParser extends AbstractMethodOptionParser i
if (options.has(helpOpt))
return this;
if (!options.has(paymentMethodIdOpt))
if (!options.has(paymentMethodIdOpt) || options.valueOf(paymentMethodIdOpt).isEmpty())
throw new IllegalArgumentException("no payment method id specified");
return this;

View File

@ -44,7 +44,7 @@ public class GetTradeOptionParser extends AbstractMethodOptionParser implements
if (options.has(helpOpt))
return this;
if (!options.has(tradeIdOpt))
if (!options.has(tradeIdOpt) || options.valueOf(tradeIdOpt).isEmpty())
throw new IllegalArgumentException("no trade id specified");
return this;

View File

@ -38,7 +38,7 @@ public class GetTransactionOptionParser extends AbstractMethodOptionParser imple
if (options.has(helpOpt))
return this;
if (!options.has(txIdOpt))
if (!options.has(txIdOpt) || options.valueOf(txIdOpt).isEmpty())
throw new IllegalArgumentException("no tx id specified");
return this;

View File

@ -42,10 +42,10 @@ public class RegisterDisputeAgentOptionParser extends AbstractMethodOptionParser
if (options.has(helpOpt))
return this;
if (!options.has(disputeAgentTypeOpt))
if (!options.has(disputeAgentTypeOpt) || options.valueOf(disputeAgentTypeOpt).isEmpty())
throw new IllegalArgumentException("no dispute agent type specified");
if (!options.has(registrationKeyOpt))
if (!options.has(registrationKeyOpt) || options.valueOf(registrationKeyOpt).isEmpty())
throw new IllegalArgumentException("no registration key specified");
return this;

View File

@ -38,7 +38,7 @@ public class RemoveWalletPasswordOptionParser extends AbstractMethodOptionParser
if (options.has(helpOpt))
return this;
if (!options.has(passwordOpt))
if (!options.has(passwordOpt) || options.valueOf(passwordOpt).isEmpty())
throw new IllegalArgumentException("no password specified");
return this;

View File

@ -48,10 +48,10 @@ public class SendBsqOptionParser extends AbstractMethodOptionParser implements M
if (options.has(helpOpt))
return this;
if (!options.has(addressOpt))
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
throw new IllegalArgumentException("no bsq address specified");
if (!options.has(amountOpt))
if (!options.has(amountOpt) || options.valueOf(amountOpt).isEmpty())
throw new IllegalArgumentException("no bsq amount specified");
return this;

View File

@ -53,10 +53,10 @@ public class SendBtcOptionParser extends AbstractMethodOptionParser implements M
if (options.has(helpOpt))
return this;
if (!options.has(addressOpt))
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
throw new IllegalArgumentException("no btc address specified");
if (!options.has(amountOpt))
if (!options.has(amountOpt) || options.valueOf(amountOpt).isEmpty())
throw new IllegalArgumentException("no btc amount specified");
return this;

View File

@ -39,7 +39,7 @@ public class SetTxFeeRateOptionParser extends AbstractMethodOptionParser impleme
if (options.has(helpOpt))
return this;
if (!options.has(feeRateOpt))
if (!options.has(feeRateOpt) || options.valueOf(feeRateOpt).isEmpty())
throw new IllegalArgumentException("no tx fee rate specified");
return this;

View File

@ -44,7 +44,7 @@ public class SetWalletPasswordOptionParser extends AbstractMethodOptionParser im
if (options.has(helpOpt))
return this;
if (!options.has(passwordOpt))
if (!options.has(passwordOpt) || options.valueOf(passwordOpt).isEmpty())
throw new IllegalArgumentException("no password specified");
return this;

View File

@ -47,10 +47,10 @@ public class TakeOfferOptionParser extends AbstractMethodOptionParser implements
if (options.has(helpOpt))
return this;
if (!options.has(offerIdOpt))
if (!options.has(offerIdOpt) || options.valueOf(offerIdOpt).isEmpty())
throw new IllegalArgumentException("no offer id specified");
if (!options.has(paymentAccountIdOpt))
if (!options.has(paymentAccountIdOpt) || options.valueOf(paymentAccountIdOpt).isEmpty())
throw new IllegalArgumentException("no payment account id specified");
return this;

View File

@ -44,7 +44,7 @@ public class UnlockWalletOptionParser extends AbstractMethodOptionParser impleme
if (options.has(helpOpt))
return this;
if (!options.has(passwordOpt))
if (!options.has(passwordOpt) || options.valueOf(passwordOpt).isEmpty())
throw new IllegalArgumentException("no password specified");
if (!options.has(unlockTimeoutOpt) || options.valueOf(unlockTimeoutOpt) <= 0)

View File

@ -48,10 +48,10 @@ public class WithdrawFundsOptionParser extends AbstractMethodOptionParser implem
if (options.has(helpOpt))
return this;
if (!options.has(tradeIdOpt))
if (!options.has(tradeIdOpt) || options.valueOf(tradeIdOpt).isEmpty())
throw new IllegalArgumentException("no trade id specified");
if (!options.has(addressOpt))
if (!options.has(addressOpt) || options.valueOf(addressOpt).isEmpty())
throw new IllegalArgumentException("no destination address specified");
return this;