-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cmd_folder_info.go
54 lines (51 loc) · 1.14 KB
/
cmd_folder_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
52
53
54
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/urfave/cli/v2"
)
func init() {
command := &cli.Command{
Name: "folder_info",
Aliases: []string{},
Usage: "Show folder information for the paper",
Action: func(c *cli.Context) error {
if !c.Args().Present() {
cli.ShowCommandHelp(c, "folder_info")
return nil
}
dboxpaper := app.Metadata["dboxpaper"].(*DboxPaper)
var in, out bytes.Buffer
err := json.NewEncoder(&in).Encode(map[string]interface{}{"doc_id": c.Args().First()})
if err != nil {
return err
}
err = dboxpaper.doAPI(
context.Background(),
http.MethodPost,
"/2/paper/docs/get_folder_info",
&request{
ct: "application/json",
in: &in,
out: &out,
})
if err != nil {
return err
}
var folderinfo FolderInfo
err = json.NewDecoder(&out).Decode(&folderinfo)
if err != nil {
return err
}
for _, folder := range folderinfo.Folders {
fmt.Fprintf(c.App.Writer, "%s %s\n", folder.ID, folder.Name)
}
return nil
},
}
command.BashComplete = docIDCompletion
app.Commands = append(app.Commands, command)
}