1 package org
.asamk
.signal
.commands
;
3 import net
.sourceforge
.argparse4j
.impl
.Arguments
;
4 import net
.sourceforge
.argparse4j
.inf
.MutuallyExclusiveGroup
;
5 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
6 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
8 import org
.asamk
.signal
.manager
.Manager
;
11 import java
.io
.IOException
;
13 public class UpdateProfileCommand
implements LocalCommand
{
16 public void attachToSubparser(final Subparser subparser
) {
17 final MutuallyExclusiveGroup avatarOptions
= subparser
.addMutuallyExclusiveGroup().required(true);
18 avatarOptions
.addArgument("--avatar").help("Path to new profile avatar");
19 avatarOptions
.addArgument("--remove-avatar").action(Arguments
.storeTrue());
21 subparser
.addArgument("--name").required(true).help("New profile name");
23 subparser
.help("Set a name and avatar image for the user profile");
27 public int handleCommand(final Namespace ns
, final Manager m
) {
28 if (!m
.isRegistered()) {
29 System
.err
.println("User is not registered.");
33 String name
= ns
.getString("name");
34 String avatarPath
= ns
.getString("avatar");
35 boolean removeAvatar
= ns
.getBoolean("remove_avatar");
38 File avatarFile
= removeAvatar ?
null : new File(avatarPath
);
39 m
.setProfile(name
, avatarFile
);
40 } catch (IOException e
) {
41 System
.err
.println("UpdateAccount error: " + e
.getMessage());