NewCollectionUpdateCmd returns a command for adding new items to a collection.
()
| 172 | |
| 173 | // NewCollectionUpdateCmd returns a command for adding new items to a collection. |
| 174 | func NewCollectionUpdateCmd() *cobra.Command { |
| 175 | return &cobra.Command{ |
| 176 | Use: "update [collection id] [ioc]...", |
| 177 | Short: "Add new items to a collection.", |
| 178 | Args: cobra.MinimumNArgs(2), |
| 179 | Long: updateCollectionCmdHelp, |
| 180 | Example: updateCollectionExample, |
| 181 | |
| 182 | RunE: func(cmd *cobra.Command, args []string) error { |
| 183 | c, err := NewAPIClient() |
| 184 | if err != nil { |
| 185 | return err |
| 186 | } |
| 187 | p, err := NewPrinter(cmd) |
| 188 | if err != nil { |
| 189 | return err |
| 190 | } |
| 191 | |
| 192 | collection := vt.NewObjectWithID("collection", args[0]) |
| 193 | reader := utils.StringReaderFromCmdArgs(args[1:]) |
| 194 | collection.SetData("raw_items", rawFromReader(reader)) |
| 195 | |
| 196 | if err := c.PatchObject(vt.URL("collections/%s", args[0]), collection); err != nil { |
| 197 | return err |
| 198 | } |
| 199 | |
| 200 | if viper.GetBool("identifiers-only") { |
| 201 | fmt.Printf("%s\n", collection.ID()) |
| 202 | } else { |
| 203 | if err := p.PrintObject(collection); err != nil { |
| 204 | return err |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | return nil |
| 209 | }, |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | var removeCollectionItemsCmdHelp = `Remove items from a collection. |
| 214 |
no test coverage detected