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()
19 avatarOptions
.addArgument("--avatar")
20 .help("Path to new profile avatar");
21 avatarOptions
.addArgument("--remove-avatar")
22 .action(Arguments
.storeTrue());
24 subparser
.addArgument("--name")
26 .help("New profile name");
28 subparser
.help("Set a name and avatar image for the user profile");
32 public int handleCommand(final Namespace ns
, final Manager m
) {
33 if (!m
.isRegistered()) {
34 System
.err
.println("User is not registered.");
38 String name
= ns
.getString("name");
39 String avatarPath
= ns
.getString("avatar");
40 boolean removeAvatar
= ns
.getBoolean("remove_avatar");
43 File avatarFile
= removeAvatar ?
null : new File(avatarPath
);
44 m
.setProfile(name
, avatarFile
);
45 } catch (IOException e
) {
46 System
.err
.println("UpdateAccount error: " + e
.getMessage());