Make name optional for updateContact

Fixes #676
This commit is contained in:
AsamK 2021-08-05 18:00:05 +02:00
parent b1ebdc8343
commit 8dced20b0f

View file

@ -18,17 +18,13 @@ public class UpdateContactCommand implements LocalCommand {
public void attachToSubparser(final Subparser subparser) { public void attachToSubparser(final Subparser subparser) {
subparser.help("Update the details of a given contact"); subparser.help("Update the details of a given contact");
subparser.addArgument("number").help("Contact number"); subparser.addArgument("number").help("Contact number");
subparser.addArgument("-n", "--name").required(true).help("New contact name"); subparser.addArgument("-n", "--name").help("New contact name");
subparser.addArgument("-e", "--expiration") subparser.addArgument("-e", "--expiration").type(int.class).help("Set expiration time of messages (seconds)");
.required(false)
.type(int.class)
.help("Set expiration time of messages (seconds)");
} }
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
var number = ns.getString("number"); var number = ns.getString("number");
var name = ns.getString("name");
try { try {
var expiration = ns.getInt("expiration"); var expiration = ns.getInt("expiration");
@ -36,7 +32,10 @@ public class UpdateContactCommand implements LocalCommand {
m.setExpirationTimer(number, expiration); m.setExpirationTimer(number, expiration);
} }
m.setContactName(number, name); var name = ns.getString("name");
if (name != null) {
m.setContactName(number, name);
}
} catch (InvalidNumberException e) { } catch (InvalidNumberException e) {
throw new UserErrorException("Invalid contact number: " + e.getMessage()); throw new UserErrorException("Invalid contact number: " + e.getMessage());
} catch (IOException e) { } catch (IOException e) {