-
Notifications
You must be signed in to change notification settings - Fork 0
/
components_info.go
51 lines (40 loc) · 1.35 KB
/
components_info.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
// 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 componentsInfoCmd = &cobra.Command{
Use: "info [Type] [ComponentID]",
Short: "Get information about a network component.",
Long: `components info can be used to retrieve information about a network component.`,
Example: `$ ttnctl components info handler test
INFO Found network component
Component ID: test
Type: handler
Created: 2016-10-06 09:52:28.766 +0000 UTC
`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 2, 2)
account := util.GetAccount(ctx)
component, err := account.FindComponent(args[0], args[1])
if err != nil {
ctx.WithError(err).WithField("type", args[0]).WithField("id", args[1]).Fatal("Could not find component")
}
ctx.Info("Found network component")
fmt.Println()
fmt.Printf("Component ID: %s\n", component.ID)
fmt.Printf("Type: %s\n", component.Type)
fmt.Printf("Created: %s\n", component.Created)
if len(component.Collaborators) > 0 {
fmt.Println()
fmt.Println("Collaborators:")
printCollaborators(component.Collaborators)
}
},
}
func init() {
componentsCmd.AddCommand(componentsInfoCmd)
}