-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.go
90 lines (78 loc) · 2.16 KB
/
profile.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"context"
"encoding/json"
"fmt"
comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/api/bsky"
"github.com/urfave/cli/v2"
"io/ioutil"
"os"
)
func doShowProfile(cCtx *cli.Context) error {
if cCtx.Args().Present() {
return cli.ShowSubcommandHelp(cCtx)
}
xrpcc, err := makeXRPCC(cCtx)
if err != nil {
return fmt.Errorf("cannot create client: %w", err)
}
arg := cCtx.String("handle")
if arg == "" {
arg = xrpcc.Auth.Handle
}
profile, err := bsky.ActorGetProfile(context.TODO(), xrpcc, arg)
if err != nil {
return fmt.Errorf("cannot get profile: %w", err)
}
if cCtx.Bool("json") {
json.NewEncoder(os.Stdout).Encode(profile)
return nil
}
fmt.Printf("Did: %s\n", profile.Did)
fmt.Printf("Handle: %s\n", profile.Handle)
fmt.Printf("DisplayName: %s\n", stringp(profile.DisplayName))
fmt.Printf("Description: %s\n", stringp(profile.Description))
fmt.Printf("Follows: %d\n", int64p(profile.FollowsCount))
fmt.Printf("Followers: %d\n", int64p(profile.FollowersCount))
fmt.Printf("Avatar: %s\n", stringp(profile.Avatar))
fmt.Printf("Banner: %s\n", stringp(profile.Banner))
return nil
}
func doLogin(cCtx *cli.Context) error {
fp, _ := cCtx.App.Metadata["path"].(string)
var cfg config
cfg.Host = cCtx.String("host")
cfg.Handle = cCtx.Args().Get(0)
cfg.Password = cCtx.Args().Get(1)
if cfg.Handle == "" || cfg.Password == "" {
cli.ShowSubcommandHelpAndExit(cCtx, 1)
}
b, err := json.MarshalIndent(&cfg, "", " ")
if err != nil {
return fmt.Errorf("cannot make config file: %w", err)
}
err = ioutil.WriteFile(fp, b, 0644)
if err != nil {
return fmt.Errorf("cannot write config file: %w", err)
}
return nil
}
func doShowSession(cCtx *cli.Context) error {
xrpcc, err := makeXRPCC(cCtx)
if err != nil {
return fmt.Errorf("cannot create client: %w", err)
}
session, err := comatproto.ServerGetSession(context.TODO(), xrpcc)
if err != nil {
return err
}
if cCtx.Bool("json") {
json.NewEncoder(os.Stdout).Encode(session)
return nil
}
fmt.Printf("Did: %s\n", session.Did)
fmt.Printf("Email: %s\n", stringp(session.Email))
fmt.Printf("Handle: %s\n", session.Handle)
return nil
}