-
Notifications
You must be signed in to change notification settings - Fork 0
/
applications_list.go
60 lines (49 loc) · 1.43 KB
/
applications_list.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
// 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/gosuri/uitable"
"github.com/spf13/cobra"
)
var applicationsListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List applications",
Long: `ttnctl applications list can be used to list applications.`,
Example: `$ ttnctl applications list
INFO Found one application:
ID Description EUIs Access Keys Collaborators
1 test Test application 1 1 1
`,
Run: func(cmd *cobra.Command, args []string) {
assertArgsLength(cmd, args, 0, 0)
account := util.GetAccount(ctx)
apps, err := account.ListApplications()
if err != nil {
ctx.WithError(err).Fatal("Could not list applications")
}
switch len(apps) {
case 0:
ctx.Info("You don't have any applications")
return
case 1:
ctx.Info("Found one application:")
default:
ctx.Infof("Found %d applications:", len(apps))
}
table := uitable.New()
table.MaxColWidth = 70
table.AddRow("", "ID", "Description", "EUIs", "Access Keys", "Collaborators")
for i, app := range apps {
table.AddRow(i+1, app.ID, app.Name, len(app.EUIs), len(app.AccessKeys), len(app.Collaborators))
}
fmt.Println()
fmt.Println(table)
fmt.Println()
},
}
func init() {
applicationsCmd.AddCommand(applicationsListCmd)
}