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
;
9 import org
.whispersystems
.libsignal
.util
.guava
.Optional
;
12 import java
.io
.IOException
;
14 public class UpdateProfileCommand
implements LocalCommand
{
17 public void attachToSubparser(final Subparser subparser
) {
18 final MutuallyExclusiveGroup avatarOptions
= subparser
.addMutuallyExclusiveGroup();
19 avatarOptions
.addArgument("--avatar").help("Path to new profile avatar");
20 avatarOptions
.addArgument("--remove-avatar").action(Arguments
.storeTrue());
22 subparser
.addArgument("--name").required(true).help("New profile name");
24 subparser
.help("Set a name and avatar image for the user profile");
28 public int handleCommand(final Namespace ns
, final Manager m
) {
29 String name
= ns
.getString("name");
30 String avatarPath
= ns
.getString("avatar");
31 boolean removeAvatar
= ns
.getBoolean("remove_avatar");
34 Optional
<File
> avatarFile
= removeAvatar
36 : avatarPath
== null ?
null : Optional
.of(new File(avatarPath
));
37 m
.setProfile(name
, avatarFile
);
38 } catch (IOException e
) {
39 System
.err
.println("UpdateAccount error: " + e
.getMessage());