1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-01 12:34:28 +00:00
arikawa/utils/generate-option-marshalers.sh
2021-12-29 11:10:59 -08:00

34 lines
602 B
Bash
Executable file

#!/usr/bin/env bash
types=(
SubcommandOption
SubcommandGroupOption
StringOption
IntegerOption
BooleanOption
UserOption
ChannelOption
RoleOption
MentionableOption
NumberOption
)
for ((i = 0; i < ${#types[@]}; i++)); {
recv=$(head -c1 <<< "${types[$i]}" | tr "[:upper:]" "[:lower:]")
cat<<EOF
// MarshalJSON marshals ${types[$i]} to JSON with the "type" field.
func (${recv} *${types[$i]}) MarshalJSON() ([]byte, error) {
type raw ${types[$i]}
return json.Marshal(struct {
Type CommandOptionType \`json:"type"\`
*raw
}{
Type: ${recv}.Type(),
raw: (*raw)(${recv}),
})
}
EOF
}