|
| 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 dashboard |
| 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/dashboard" |
| 26 | + "github.com/sirupsen/logrus" |
| 27 | + "github.com/spf13/cobra" |
| 28 | +) |
| 29 | + |
| 30 | +var deleteFlags struct { |
| 31 | + id string |
| 32 | +} |
| 33 | + |
| 34 | +func initDeleteCommand() *cobra.Command { |
| 35 | + deleteCommand := &cobra.Command{ |
| 36 | + Use: "delete", |
| 37 | + Short: "Delete a dashboard", |
| 38 | + Long: "Delete a dashboard from Arduino IoT Cloud", |
| 39 | + Run: runDeleteCommand, |
| 40 | + } |
| 41 | + deleteCommand.Flags().StringVarP(&deleteFlags.id, "id", "i", "", "Dashboard ID") |
| 42 | + deleteCommand.MarkFlagRequired("id") |
| 43 | + return deleteCommand |
| 44 | +} |
| 45 | + |
| 46 | +func runDeleteCommand(cmd *cobra.Command, args []string) { |
| 47 | + logrus.Infof("Deleting dashboard %s\n", deleteFlags.id) |
| 48 | + |
| 49 | + params := &dashboard.DeleteParams{ID: deleteFlags.id} |
| 50 | + err := dashboard.Delete(params) |
| 51 | + if err != nil { |
| 52 | + feedback.Errorf("Error during dashboard delete: %v", err) |
| 53 | + os.Exit(errorcodes.ErrGeneric) |
| 54 | + } |
| 55 | + |
| 56 | + logrus.Info("Dashboard successfully deleted") |
| 57 | +} |
0 commit comments