tangled
alpha
login
or
join now
bnewbold.net
/
cobalt
13
fork
atom
go scratch code for atproto
13
fork
atom
overview
issues
pulls
pipelines
glot pull tweaks
bnewbold.net
5 months ago
2dc28967
29218435
+21
-7
1 changed file
expand all
collapse all
unified
split
cmd
glot
pull.go
+21
-7
cmd/glot/pull.go
···
11
11
"github.com/bluesky-social/indigo/api/agnostic"
12
12
"github.com/bluesky-social/indigo/atproto/client"
13
13
"github.com/bluesky-social/indigo/atproto/identity"
14
14
+
"github.com/bluesky-social/indigo/atproto/data"
14
15
"github.com/bluesky-social/indigo/atproto/lexicon"
15
16
"github.com/bluesky-social/indigo/atproto/syntax"
16
17
"tangled.sh/bnewbold.net/cobalt/atproto/netclient"
···
38
39
&cli.StringFlag{
39
40
Name: "output-dir",
40
41
Aliases: []string{"o"},
41
41
-
Value: "./lexicons/",
42
42
Usage: "write schema files to specific directory",
43
43
Sources: cli.EnvVars("LEXICONS_DIR"),
44
44
},
···
78
78
if !cmd.Bool("update") {
79
79
_, err := os.Stat(fpath)
80
80
if err == nil {
81
81
-
return fmt.Errorf("output file already exists: %s", fpath)
81
81
+
fmt.Printf(" 🟣 %s\n", nsid)
82
82
+
return nil
82
83
}
83
84
}
84
85
···
95
96
if err != nil {
96
97
return err
97
98
}
98
98
-
slog.Info("fetched NSID schema record", "nsid", nsid, "cid", cid)
99
99
+
slog.Debug("fetched NSID schema record", "nsid", nsid, "cid", cid)
99
100
100
100
-
return writeLexiconFile(ctx, cmd, nsid, fpath, rec)
101
101
+
if err := writeLexiconFile(ctx, cmd, nsid, fpath, rec); err != nil {
102
102
+
return err
103
103
+
}
104
104
+
fmt.Printf(" 🟢 %s\n", nsid)
105
105
+
return nil
101
106
}
102
107
103
108
func writeLexiconFile(ctx context.Context, cmd *cli.Command, nsid syntax.NSID, fpath string, rec json.RawMessage) error {
···
116
121
return err
117
122
}
118
123
119
119
-
b, err := json.MarshalIndent(rec, "", " ")
124
124
+
// remove $type (from record)
125
125
+
d, err := data.UnmarshalJSON(rec)
126
126
+
if err != nil {
127
127
+
return err
128
128
+
}
129
129
+
delete(d, "$type")
130
130
+
131
131
+
b, err := json.MarshalIndent(d, "", " ")
120
132
if err != nil {
121
133
return err
122
134
}
···
126
138
return err
127
139
}
128
140
129
129
-
slog.Info("wrote NSID schema record to disk", "nsid", nsid, "path", fpath)
141
141
+
slog.Debug("wrote NSID schema record to disk", "nsid", nsid, "path", fpath)
130
142
return nil
131
143
}
132
144
···
173
185
if !cmd.Bool("update") {
174
186
_, err := os.Stat(fpath)
175
187
if err == nil {
176
176
-
return fmt.Errorf("output file already exists: %s", fpath)
188
188
+
fmt.Printf(" 🟣 %s\n", nsid)
189
189
+
continue
177
190
}
178
191
}
179
192
if err := writeLexiconFile(ctx, cmd, nsid, fpath, *rec.Value); err != nil {
180
193
return nil
181
194
}
195
195
+
fmt.Printf(" 🟢 %s\n", nsid)
182
196
}
183
197
if resp.Cursor != nil && *resp.Cursor != "" {
184
198
cursor = *resp.Cursor