This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
/
applications_add.go
65 lines (53 loc) · 1.85 KB
/
applications_add.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright © 2016 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 (
"github.com/TheThingsNetwork/ttn/core/types"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)
var applicationsAddCmd = &cobra.Command{
Use: "add [AppID] [Description]",
Short: "Add a new application",
Long: `ttnctl applications add can be used to add a new application to your account.`,
Example: `$ ttnctl applications add test "Test application"
INFO Added Application
INFO Selected Current Application
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
cmd.UsageFunc()(cmd)
return
}
var euis []types.AppEUI
euiStrings, err := cmd.Flags().GetStringSlice("app-eui")
if err != nil {
ctx.WithError(err).Fatal("Could not read app-eui options")
}
for _, euiString := range euiStrings {
eui, err := types.ParseAppEUI(euiString)
if err != nil {
ctx.WithError(err).Fatal("Could not read app-eui")
}
euis = append(euis, eui)
}
account := util.GetAccount(ctx)
app, err := account.CreateApplication(args[0], args[1], euis)
if err != nil {
ctx.WithError(err).Fatal("Could not add application")
}
util.ForceRefreshToken(ctx)
ctx.Info("Added Application")
skipSelect, _ := cmd.Flags().GetBool("skip-select")
if !skipSelect {
util.SetApp(ctx, app.ID, app.EUIs[0])
}
ctx.Info("Selected Current Application")
},
}
func init() {
applicationsCmd.AddCommand(applicationsAddCmd)
applicationsAddCmd.Flags().StringSlice("app-eui", []string{}, "LoRaWAN AppEUI to register with application")
applicationsAddCmd.Flags().Bool("skip-select", false, "Do not select this application (also adds --skip-register)")
applicationsAddCmd.Flags().Bool("skip-register", false, "Do not register application with the Handler")
}