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_pf.go
86 lines (73 loc) · 1.96 KB
/
applications_pf.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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 (
"fmt"
"github.com/TheThingsNetwork/ttn/ttnctl/util"
"github.com/spf13/cobra"
)
var applicationsPayloadFormatCmd = &cobra.Command{
Use: "pf",
Short: "Show the payload format",
Long: `ttnctl applications pf shows the payload format to handle
binary payload.`,
Example: `$ ttnctl applications pf
INFO Discovering Handler...
INFO Connecting with Handler...
INFO Found application
INFO Custom decoder function
function Decoder(bytes, port) {
var decoded = {};
if (port === 1) {
decoded.led = bytes[0];
}
return decoded;
}
INFO No custom converter function
INFO No custom validator function
INFO No custom encoder function
`,
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()
app, err := manager.GetApplication(appID)
if err != nil {
ctx.WithError(err).Fatal("Could not get application.")
}
ctx.Info("Found application")
switch app.PayloadFormat {
case "custom":
if app.Decoder != "" {
ctx.Info("Custom decoder function")
fmt.Println(app.Decoder)
} else {
ctx.Info("No custom decoder function")
}
if app.Converter != "" {
ctx.Info("Custom converter function")
fmt.Println(app.Converter)
} else {
ctx.Info("No custom converter function")
}
if app.Validator != "" {
ctx.Info("Custom validator function")
fmt.Println(app.Validator)
} else {
ctx.Info("No custom validator function")
}
if app.Encoder != "" {
ctx.Info("Custom encoder function")
fmt.Println(app.Encoder)
} else {
ctx.Info("No custom encoder function")
}
default:
ctx.Infof("Payload format set to %s", app.PayloadFormat)
}
},
}
func init() {
applicationsCmd.AddCommand(applicationsPayloadFormatCmd)
}