|
| 1 | +// This file is part of arduino-cloud-cli. |
| 2 | +// |
| 3 | +// Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU Affero General Public License as published |
| 7 | +// by the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU Affero General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU Affero General Public License |
| 16 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +package tag |
| 19 | + |
| 20 | +import ( |
| 21 | + "os" |
| 22 | + |
| 23 | + "github.com/arduino/arduino-cli/cli/errorcodes" |
| 24 | + "github.com/arduino/arduino-cli/cli/feedback" |
| 25 | + "github.com/arduino/arduino-cloud-cli/command/tag" |
| 26 | + "github.com/sirupsen/logrus" |
| 27 | + "github.com/spf13/cobra" |
| 28 | +) |
| 29 | + |
| 30 | +var deleteTagsFlags struct { |
| 31 | + id string |
| 32 | + keys []string |
| 33 | +} |
| 34 | + |
| 35 | +func InitDeleteTagsCommand() *cobra.Command { |
| 36 | + deleteTagsCommand := &cobra.Command{ |
| 37 | + Use: "delete-tags", |
| 38 | + Short: "Delete tags of a device", |
| 39 | + Long: "Delete tags of a device of Arduino IoT Cloud", |
| 40 | + Run: runDeleteTagsCommand, |
| 41 | + } |
| 42 | + |
| 43 | + deleteTagsCommand.Flags().StringVarP(&deleteTagsFlags.id, "id", "i", "", "Device ID") |
| 44 | + deleteTagsCommand.Flags().StringSliceVarP(&deleteTagsFlags.keys, "keys", "k", nil, "Comma-separated list of keys of tags to delete") |
| 45 | + |
| 46 | + deleteTagsCommand.MarkFlagRequired("id") |
| 47 | + deleteTagsCommand.MarkFlagRequired("keys") |
| 48 | + return deleteTagsCommand |
| 49 | +} |
| 50 | + |
| 51 | +func runDeleteTagsCommand(cmd *cobra.Command, args []string) { |
| 52 | + logrus.Infof("Deleting tags with keys %s\n", deleteTagsFlags.keys) |
| 53 | + |
| 54 | + params := &tag.DeleteTagsParams{ |
| 55 | + ID: deleteTagsFlags.id, |
| 56 | + Keys: deleteTagsFlags.keys, |
| 57 | + Resource: tag.Device, |
| 58 | + } |
| 59 | + |
| 60 | + err := tag.DeleteTags(params) |
| 61 | + if err != nil { |
| 62 | + feedback.Errorf("Error during device delete-tags: %v", err) |
| 63 | + os.Exit(errorcodes.ErrGeneric) |
| 64 | + } |
| 65 | + |
| 66 | + logrus.Info("Tags successfully deleted") |
| 67 | +} |
0 commit comments