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();
18 avatarOptions
.addArgument("--avatar")
19 .help("Path to new profile avatar");
20 avatarOptions
.addArgument("--remove-avatar")
21 .action(Arguments
.storeTrue());
23 subparser
.addArgument("--name")
24 .help("New profile name");
26 subparser
.help("Set a name and/or avatar image for the user profile");
30 public int handleCommand(final Namespace ns
, final Manager m
) {
31 if (!m
.isRegistered()) {
32 System
.err
.println("User is not registered.");
36 String name
= ns
.getString("name");
40 m
.setProfileName(name
);
41 } catch (IOException e
) {
42 System
.err
.println("UpdateAccount error: " + e
.getMessage());
47 String avatarPath
= ns
.getString("avatar");
49 if (avatarPath
!= null) {
50 File avatarFile
= new File(avatarPath
);
53 m
.setProfileAvatar(avatarFile
);
54 } catch (IOException e
) {
55 System
.err
.println("UpdateAccount error: " + e
.getMessage());
60 boolean removeAvatar
= ns
.getBoolean("remove_avatar");
64 m
.removeProfileAvatar();
65 } catch (IOException e
) {
66 System
.err
.println("UpdateAccount error: " + e
.getMessage());