This repository was archived by the owner on Nov 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcmd_readme.go
More file actions
60 lines (51 loc) · 1.33 KB
/
cmd_readme.go
File metadata and controls
60 lines (51 loc) · 1.33 KB
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
//go:build ignore
// +build ignore
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"reflect"
"sort"
"strings"
"text/tabwriter"
"github.com/AlekSi/rtm"
)
func main() {
log.SetFlags(0)
keyF := flag.String("key", "", "API key")
secretF := flag.String("secret", "", "API secret")
flag.Parse()
if *keyF == "" || *secretF == "" {
log.Fatal("Both -key and -secret flags should be used.")
}
client := &rtm.Client{
APIKey: *keyF,
APISecret: *secretF,
}
methods, err := client.Reflection().GetMethods(context.Background())
if err != nil {
log.Fatal(err)
}
sort.Strings(methods)
clientT := reflect.TypeOf(client)
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug)
for _, method := range methods {
docMethod := "TODO"
parts := strings.SplitN(method, ".", 3)
serviceName := strings.ToUpper(parts[1][:1]) + parts[1][1:]
m, ok := clientT.MethodByName(serviceName)
if ok {
methodName := strings.ToUpper(parts[2][:1]) + parts[2][1:]
m, ok = m.Type.Out(0).MethodByName(methodName)
if ok {
serviceName += "Service"
docMethod = fmt.Sprintf("[`%[1]s.%[2]s`](https://pkg.go.dev/github.com/AlekSi/rtm#%[1]s.%[2]s)", serviceName, methodName)
}
}
fmt.Fprintf(w, "| [`%[1]s`](https://www.rememberthemilk.com/services/api/methods/%[1]s.rtm)\t %s\n", method, docMethod)
}
w.Flush()
}