-
Notifications
You must be signed in to change notification settings - Fork 0
/
applications_register.go
42 lines (34 loc) · 1.13 KB
/
applications_register.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
// 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 (
ttnlog "github.com/TheThingsNetwork/go-utils/log"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)
var applicationsRegisterCmd = &cobra.Command{
Use: "register",
Short: "Register this application with the handler",
Long: `ttnctl applications register can be used to register this application with the handler.`,
Example: `$ ttnctl applications register
INFO Discovering Handler...
INFO Connecting with Handler...
INFO Registered application AppID=test
`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 0, 0)
appID := util.GetAppID(ctx)
conn, manager := util.GetHandlerManager(ctx, appID)
defer conn.Close()
err := manager.RegisterApplication(appID)
if err != nil {
ctx.WithError(err).Fatal("Could not register application")
}
ctx.WithFields(ttnlog.Fields{
"AppID": appID,
}).Infof("Registered application")
},
}
func init() {
applicationsCmd.AddCommand(applicationsRegisterCmd)
}