()
| 136 | } |
| 137 | |
| 138 | func updatePartialCmd() *cobra.Command { |
| 139 | cmd := &cobra.Command{ |
| 140 | Use: "update-user-partial --user [user-id] --set [raw-json] --unset [property-names]", |
| 141 | Short: "Partially update a user", |
| 142 | Long: heredoc.Doc(` |
| 143 | Updates an existing user. The 'set' property is a comma separated list of key value pairs. |
| 144 | The 'unset' property is a comma separated list of property names. |
| 145 | `), |
| 146 | Example: heredoc.Doc(` |
| 147 | # Set a user's role to 'admin' and set 'age' to 21. At the same time, remove 'haircolor' and 'height'. |
| 148 | $ stream-cli chat update-user-partial --user-id my-user-1 --set '{"role":"admin","age":21}' --unset haircolor,height |
| 149 | `), |
| 150 | RunE: func(cmd *cobra.Command, args []string) error { |
| 151 | c, err := config.GetConfig(cmd).GetClient(cmd) |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | |
| 156 | userID, _ := cmd.Flags().GetString("user-id") |
| 157 | update, err := utils.GetPartialUpdateParam(cmd.Flags()) |
| 158 | if err != nil { |
| 159 | return err |
| 160 | } |
| 161 | |
| 162 | _, err = c.PartialUpdateUser(cmd.Context(), stream.PartialUserUpdate{ID: userID, Set: update.Set, Unset: update.Unset}) |
| 163 | if err != nil { |
| 164 | return err |
| 165 | } |
| 166 | |
| 167 | cmd.Printf("Successfully updated user [%s]\n", userID) |
| 168 | return nil |
| 169 | }, |
| 170 | } |
| 171 | |
| 172 | fl := cmd.Flags() |
| 173 | fl.StringP("user-id", "i", "", "[required] Channel ID") |
| 174 | fl.StringP("set", "s", "", "[optional] Raw JSON of key-value pairs to set") |
| 175 | fl.StringP("unset", "u", "", "[optional] Comma separated list of properties to unset") |
| 176 | _ = cmd.MarkFlagRequired("user-id") |
| 177 | |
| 178 | return cmd |
| 179 | } |
| 180 | |
| 181 | func deleteCmd() *cobra.Command { |
| 182 | cmd := &cobra.Command{ |
no test coverage detected