@@ -9,26 +9,43 @@ import (
99
1010// MergeCmd represents the merge command for users
1111var MergeCmd = & cobra.Command {
12- Use : "merge" ,
13- Short : "Merge two users" ,
14- Args : cobra .ExactArgs (2 ),
15- Example : "iterablectl users merge <source_email> <destination_email>" ,
12+ Use : "merge" ,
13+ Short : "Merge two users" ,
14+ Example : `iterablectl users merge --from-email <source email> --to-email <destination email>
15+ iterablectl users merge --from-user-id <source user id> --to-email <destination email>
16+ iterablectl users merge --from-user-id <source user id> --to-user-id <destination user id>
17+ iterablectl users merge --from-email <source > --to-user-id <destination user id>
18+ ` ,
1619 RunE : func (cmd * cobra.Command , args []string ) error {
1720 apiKey , _ := cmd .Flags ().GetString ("api-key" )
1821 client := iterable .NewClient (apiKey )
1922
20- sourceEmail := args [0 ]
21- if sourceEmail == "" {
22- return fmt .Errorf ("source email is required" )
23+ // Get flag values
24+ fromEmail , _ := cmd .Flags ().GetString ("from-email" )
25+ fromUserID , _ := cmd .Flags ().GetString ("from-user-id" )
26+ toEmail , _ := cmd .Flags ().GetString ("to-email" )
27+ toUserID , _ := cmd .Flags ().GetString ("to-user-id" )
28+
29+ // Validate that exactly one source identifier is provided
30+ if (fromEmail == "" && fromUserID == "" ) || (fromEmail != "" && fromUserID != "" ) {
31+ return fmt .Errorf ("exactly one of --source-email or --source-user-id must be specified" )
2332 }
24- destinationEmail := args [1 ]
25- if destinationEmail == "" {
26- return fmt .Errorf ("destination email is required" )
33+ if (toEmail == "" && toUserID == "" ) || (toEmail != "" && toUserID != "" ) {
34+ return fmt .Errorf ("exactly one of --to-email or --to-user-id must be specified" )
2735 }
2836
29- response , err := client .MergeUsers (sourceEmail , destinationEmail )
37+ var response * iterable.APIError
38+ var err error
39+
40+ response , err = client .MergeUsers (iterable.MergeUsersOpts {
41+ SrcEmail : fromEmail ,
42+ DstEmail : toEmail ,
43+
44+ SrcID : fromUserID ,
45+ DstID : toUserID ,
46+ })
3047 if err != nil {
31- return fmt .Errorf ("error merging users: %v " , err )
48+ return fmt .Errorf ("error merging users: %w " , err )
3249 }
3350
3451 if response .Code != "Success" {
@@ -38,3 +55,10 @@ var MergeCmd = &cobra.Command{
3855 return nil
3956 },
4057}
58+
59+ func init () {
60+ MergeCmd .Flags ().String ("from-email" , "" , "Email address of the source user to merge" )
61+ MergeCmd .Flags ().String ("from-user-id" , "" , "User ID of the source user to merge" )
62+ MergeCmd .Flags ().String ("to-email" , "" , "Email address of the destination profile to merge into" )
63+ MergeCmd .Flags ().String ("to-user-id" , "" , "User ID of the destination profile to merge into" )
64+ }
0 commit comments