1 package org
.asamk
.signal
.commands
;
3 import java
.io
.IOException
;
6 import net
.sourceforge
.argparse4j
.impl
.Arguments
;
7 import net
.sourceforge
.argparse4j
.inf
.MutuallyExclusiveGroup
;
8 import net
.sourceforge
.argparse4j
.inf
.Namespace
;
9 import net
.sourceforge
.argparse4j
.inf
.Subparser
;
10 import org
.asamk
.signal
.manager
.Manager
;
12 public class UpdateProfileCommand
implements LocalCommand
{
15 public void attachToSubparser(final Subparser subparser
) {
16 final MutuallyExclusiveGroup avatarOptions
= subparser
.addMutuallyExclusiveGroup();
17 avatarOptions
.addArgument("--avatar")
18 .help("Path to new profile avatar");
19 avatarOptions
.addArgument("--remove-avatar")
20 .action(Arguments
.storeTrue());
22 subparser
.addArgument("--name")
23 .help("New profile name");
25 subparser
.help("Set a name and/or avatar image for the user profile");
29 public int handleCommand(final Namespace ns
, final Manager m
) {
30 if (!m
.isRegistered()) {
31 System
.err
.println("User is not registered.");
35 String name
= ns
.getString("name");
39 m
.setProfileName(name
);
40 } catch (IOException e
) {
41 System
.err
.println("UpdateAccount error: " + e
.getMessage());
46 String avatarPath
= ns
.getString("avatar");
48 if (avatarPath
!= null) {
49 File avatarFile
= new File(avatarPath
);
52 m
.setProfileAvatar(avatarFile
);
53 } catch (IOException e
) {
54 System
.err
.println("UpdateAccount error: " + e
.getMessage());
59 boolean removeAvatar
= ns
.getBoolean("remove_avatar");
63 m
.removeProfileAvatar();
64 } catch (IOException e
) {
65 System
.err
.println("UpdateAccount error: " + e
.getMessage());