MCPcopy Create free account
hub / github.com/GetStream/stream-cli / partialUpdateCmd

Function partialUpdateCmd

pkg/cmd/chat/message/message.go:206–252  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

204}
205
206func partialUpdateCmd() *cobra.Command {
207 cmd := &cobra.Command{
208 Use: "update-message-partial --message-id [message-id] --user [user-id] --set [raw-json] --unset [property-names]",
209 Short: "Partially update a message",
210 Long: heredoc.Doc(`
211 A partial update can be used to set and unset specific fields when it
212 is necessary to retain additional data fields on the object. AKA a patch style update.
213 `),
214 Example: heredoc.Doc(`
215 # Partially updates a message with id 'msgid-1'. Updates a custom field and removes the silent flag.
216 $ stream-cli chat update-message-partial -message-id msgid-1 --set '{"importance": "low"}' --unset silent
217 `),
218 RunE: func(cmd *cobra.Command, args []string) error {
219 c, err := config.GetConfig(cmd).GetClient(cmd)
220 if err != nil {
221 return err
222 }
223
224 msgId, _ := cmd.Flags().GetString("message-id")
225 user, _ := cmd.Flags().GetString("user")
226 update, err := utils.GetPartialUpdateParam(cmd.Flags())
227 if err != nil {
228 return err
229 }
230
231 _, err = c.PartialUpdateMessage(cmd.Context(), msgId, &stream.MessagePartialUpdateRequest{
232 UserID: user,
233 PartialUpdate: update,
234 })
235 if err != nil {
236 return err
237 }
238
239 cmd.Println("Successfully updated message.")
240 return nil
241 },
242 }
243
244 fl := cmd.Flags()
245 fl.StringP("message-id", "m", "", "[required] Message id")
246 fl.StringP("user", "u", "", "[required] User id")
247 fl.StringP("set", "s", "", "[optional] Raw JSON of key-value pairs to set")
248 fl.String("unset", "", "[optional] Comma separated list of properties to unset")
249 _ = cmd.MarkFlagRequired("message-id")
250
251 return cmd
252}
253
254func flagCmd() *cobra.Command {
255 cmd := &cobra.Command{

Callers 1

NewCmdsFunction · 0.85

Calls 4

GetConfigFunction · 0.92
GetPartialUpdateParamFunction · 0.92
GetClientMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected