-
Notifications
You must be signed in to change notification settings - Fork 0
/
gateways_delete.go
41 lines (33 loc) · 1.04 KB
/
gateways_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright © 2017 The Things Network
// Use of this source code is governed by the MIT license that can be found in the LICENSE file.
package cmd
import (
"strings"
"github.com/TheThingsNetwork/api"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)
var gatewaysDeleteCmd = &cobra.Command{
Use: "delete [GatewayID]",
Short: "Delete a gateway",
Long: `ttnctl gateways delete can be used to delete a gateway`,
Example: `$ ttnctl gateways delete test
INFO Deleted gateway Gateway ID=test
`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 1, 1)
gatewayID := strings.ToLower(args[0])
if err := api.NotEmptyAndValidID(gatewayID, "Gateway ID"); err != nil {
ctx.Fatal(err.Error())
}
account := util.GetAccount(ctx)
err := account.DeleteGateway(gatewayID)
if err != nil {
ctx.WithError(err).Fatal("Could not list gateways")
}
ctx.WithField("Gateway ID", gatewayID).Info("Deleted gateway")
},
}
func init() {
gatewaysCmd.AddCommand(gatewaysDeleteCmd)
}