-
Notifications
You must be signed in to change notification settings - Fork 44
/
cli_profile.go
125 lines (103 loc) · 3.93 KB
/
cli_profile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package cli
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cobra"
"github.com/desmos-labs/desmos/v6/x/profiles/types"
)
func GetCmdSaveProfile() *cobra.Command {
cmd := &cobra.Command{
Use: "save",
Args: cobra.NoArgs,
Short: "Save your profile",
Long: fmt.Sprintf(`
Save a new profile or edit the existing one specifying a DTag, a nickname, biography, profile picture and cover picture.
Every data given through the flags is optional.
If you are editing an existing profile you should fill only the fields that you want to edit.
The empty ones will be filled with a special [do-not-modify] flag that tells the system to not edit them.
%s tx profiles save
--%s "LeoDiCaprio" \
--%s "Leonardo Di Caprio" \
--%s "Hollywood actor. Proud environmentalist" \
--%s "https://profilePic.jpg" \
--%s "https://profileCover.jpg"
`, version.AppName, FlagDTag, FlagNickname, FlagBio, FlagProfilePic, FlagCoverPic),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
dTag, _ := cmd.Flags().GetString(FlagDTag)
nickname, _ := cmd.Flags().GetString(FlagNickname)
bio, _ := cmd.Flags().GetString(FlagBio)
profilePic, _ := cmd.Flags().GetString(FlagProfilePic)
coverPic, _ := cmd.Flags().GetString(FlagCoverPic)
msg := types.NewMsgSaveProfile(dTag, nickname, bio, profilePic, coverPic, clientCtx.FromAddress.String())
if err = msg.ValidateBasic(); err != nil {
return fmt.Errorf("message validation failed: %w", err)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
cmd.Flags().String(FlagDTag, types.DoNotModify, "DTag to be used")
cmd.Flags().String(FlagNickname, types.DoNotModify, "Nickname to be used")
cmd.Flags().String(FlagBio, types.DoNotModify, "Biography to be used")
cmd.Flags().String(FlagProfilePic, types.DoNotModify, "Profile picture")
cmd.Flags().String(FlagCoverPic, types.DoNotModify, "Cover picture")
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdDeleteProfile returns the command used to delete an existing profile
func GetCmdDeleteProfile() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Short: "Delete an existent profile related to the user's address",
Example: fmt.Sprintf(`%s tx profiles delete`, version.AppName),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := types.NewMsgDeleteProfile(clientCtx.FromAddress.String())
if err = msg.ValidateBasic(); err != nil {
return fmt.Errorf("message validation failed: %w", err)
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// --------------------------------------------------------------------------------------------------------------------
// GetCmdQueryProfile returns the command that allows to query the profile of a specific user
func GetCmdQueryProfile() *cobra.Command {
cmd := &cobra.Command{
Use: "profile [address_or_dtag]",
Short: "Retrieve the profile having the specified user address or profile dtag, if any.",
Example: fmt.Sprintf(`%s query profiles desmos12a2y7fflz6g4e5gn0mh0n9dkrzllj0q5vx7c6t
%s query profiles Alice`, version.AppName, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Profile(
context.Background(),
&types.QueryProfileRequest{User: args[0]},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}