-
Notifications
You must be signed in to change notification settings - Fork 1
/
apps.go
55 lines (49 loc) · 1010 Bytes
/
apps.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
package main
import (
"fmt"
"github.com/codegangsta/cli"
"github.com/modouwifi/md/api"
)
var cmdApps = cli.Command{
Name: "apps",
Usage: "List apps, show apps",
Action: runApps,
Subcommands: []cli.Command{
{
Name: "list",
Usage: "List installed apps",
Action: runAppsList,
},
},
}
func runApps(c *cli.Context) {
args := c.Args()
if len(args) == 0 {
cli.ShowSubcommandHelp(c)
return
}
appId := args.First()
app := getAppInfoById(appId)
fmt.Println(app)
}
func runAppsList(c *cli.Context) {
req, err := client.NewRequest("GET", "/plugin/installed_plugins")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
var result api.Apps
err = req.ToJSON(&result)
fmt.Println(result)
}
func getAppInfoById(id string) api.App {
req, err := client.NewRequest("GET", "/plugin/plugin_latest_info")
if err != nil {
fmt.Println(err)
}
req.SetCookie(config.Cookie)
req.QueryString("id=" + id)
var result api.App
err = req.ToJSON(&result)
return result
}