Add special case for 'Crud', and transform enum and struct type names

This commit is contained in:
Elara 2023-01-07 14:54:04 -08:00
parent c6b51b4705
commit df0dc254c3
3 changed files with 37 additions and 40 deletions

View File

@ -71,6 +71,7 @@ func (s *StructParser) Parse() ([]Item, error) {
if slices.Contains(s.Skip, structName) { if slices.Contains(s.Skip, structName) {
continue continue
} }
structName = s.TransformName(structName)
// If the line ends with "}", this is a struct with no fields // If the line ends with "}", this is a struct with no fields
if strings.HasSuffix(line, "}\n") { if strings.HasSuffix(line, "}\n") {
@ -97,8 +98,9 @@ func (s *StructParser) Parse() ([]Item, error) {
enumName := enumRegex.FindStringSubmatch(line)[1] enumName := enumRegex.FindStringSubmatch(line)[1]
if slices.Contains(s.Skip, enumName) { if slices.Contains(s.Skip, enumName) {
continue continue
} }
enumName = s.TransformName(enumName)
members, err := s.parseEnumMemebers() members, err := s.parseEnumMemebers()
if err != nil { if err != nil {
return nil, err return nil, err
@ -233,6 +235,8 @@ func TransformTypeGo(t string) string {
func TransformNameGo(s string) string { func TransformNameGo(s string) string {
out := "" out := ""
s = strings.ReplaceAll(s, "Crud", "CRUD")
splitName := strings.Split(s, "_") splitName := strings.Split(s, "_")
for _, segment := range splitName { for _, segment := range splitName {
switch segment { switch segment {

View File

@ -58,35 +58,35 @@ const (
UserOperationBlockPerson UserOperation = "BlockPerson" UserOperationBlockPerson UserOperation = "BlockPerson"
) )
type UserOperationCrud string type UserOperationCRUD string
const ( const (
UserOperationCrudCreateSite UserOperationCrud = "CreateSite" UserOperationCRUDCreateSite UserOperationCRUD = "CreateSite"
UserOperationCrudGetSite UserOperationCrud = "GetSite" UserOperationCRUDGetSite UserOperationCRUD = "GetSite"
UserOperationCrudEditSite UserOperationCrud = "EditSite" UserOperationCRUDEditSite UserOperationCRUD = "EditSite"
UserOperationCrudCreateCommunity UserOperationCrud = "CreateCommunity" UserOperationCRUDCreateCommunity UserOperationCRUD = "CreateCommunity"
UserOperationCrudListCommunities UserOperationCrud = "ListCommunities" UserOperationCRUDListCommunities UserOperationCRUD = "ListCommunities"
UserOperationCrudGetCommunity UserOperationCrud = "GetCommunity" UserOperationCRUDGetCommunity UserOperationCRUD = "GetCommunity"
UserOperationCrudEditCommunity UserOperationCrud = "EditCommunity" UserOperationCRUDEditCommunity UserOperationCRUD = "EditCommunity"
UserOperationCrudDeleteCommunity UserOperationCrud = "DeleteCommunity" UserOperationCRUDDeleteCommunity UserOperationCRUD = "DeleteCommunity"
UserOperationCrudRemoveCommunity UserOperationCrud = "RemoveCommunity" UserOperationCRUDRemoveCommunity UserOperationCRUD = "RemoveCommunity"
UserOperationCrudCreatePost UserOperationCrud = "CreatePost" UserOperationCRUDCreatePost UserOperationCRUD = "CreatePost"
UserOperationCrudGetPost UserOperationCrud = "GetPost" UserOperationCRUDGetPost UserOperationCRUD = "GetPost"
UserOperationCrudGetPosts UserOperationCrud = "GetPosts" UserOperationCRUDGetPosts UserOperationCRUD = "GetPosts"
UserOperationCrudEditPost UserOperationCrud = "EditPost" UserOperationCRUDEditPost UserOperationCRUD = "EditPost"
UserOperationCrudDeletePost UserOperationCrud = "DeletePost" UserOperationCRUDDeletePost UserOperationCRUD = "DeletePost"
UserOperationCrudRemovePost UserOperationCrud = "RemovePost" UserOperationCRUDRemovePost UserOperationCRUD = "RemovePost"
UserOperationCrudCreateComment UserOperationCrud = "CreateComment" UserOperationCRUDCreateComment UserOperationCRUD = "CreateComment"
UserOperationCrudGetComment UserOperationCrud = "GetComment" UserOperationCRUDGetComment UserOperationCRUD = "GetComment"
UserOperationCrudGetComments UserOperationCrud = "GetComments" UserOperationCRUDGetComments UserOperationCRUD = "GetComments"
UserOperationCrudEditComment UserOperationCrud = "EditComment" UserOperationCRUDEditComment UserOperationCRUD = "EditComment"
UserOperationCrudDeleteComment UserOperationCrud = "DeleteComment" UserOperationCRUDDeleteComment UserOperationCRUD = "DeleteComment"
UserOperationCrudRemoveComment UserOperationCrud = "RemoveComment" UserOperationCRUDRemoveComment UserOperationCRUD = "RemoveComment"
UserOperationCrudRegister UserOperationCrud = "Register" UserOperationCRUDRegister UserOperationCRUD = "Register"
UserOperationCrudGetPersonDetails UserOperationCrud = "GetPersonDetails" UserOperationCRUDGetPersonDetails UserOperationCRUD = "GetPersonDetails"
UserOperationCrudDeleteAccount UserOperationCrud = "DeleteAccount" UserOperationCRUDDeleteAccount UserOperationCRUD = "DeleteAccount"
UserOperationCrudCreatePrivateMessage UserOperationCrud = "CreatePrivateMessage" UserOperationCRUDCreatePrivateMessage UserOperationCRUD = "CreatePrivateMessage"
UserOperationCrudGetPrivateMessages UserOperationCrud = "GetPrivateMessages" UserOperationCRUDGetPrivateMessages UserOperationCRUD = "GetPrivateMessages"
UserOperationCrudEditPrivateMessage UserOperationCrud = "EditPrivateMessage" UserOperationCRUDEditPrivateMessage UserOperationCRUD = "EditPrivateMessage"
UserOperationCrudDeletePrivateMessage UserOperationCrud = "DeletePrivateMessage" UserOperationCRUDDeletePrivateMessage UserOperationCRUD = "DeletePrivateMessage"
) )

View File

@ -61,15 +61,8 @@ type LemmyWebSocketMsg struct {
// IsOneOf checks if the message is one of the given operations. // IsOneOf checks if the message is one of the given operations.
func (msg LemmyWebSocketMsg) IsOneOf(ops ...Operation) bool { func (msg LemmyWebSocketMsg) IsOneOf(ops ...Operation) bool {
for _, op := range ops { for _, op := range ops {
switch op := op.(type) { if op.Operation() == msg.Op {
case UserOperation: return true
if string(op) == msg.Op {
return true
}
case UserOperationCrud:
if string(op) == msg.Op {
return true
}
} }
} }
return false return false
@ -83,6 +76,6 @@ func (u UserOperation) Operation() string {
return string(u) return string(u)
} }
func (u UserOperationCrud) Operation() string { func (u UserOperationCRUD) Operation() string {
return string(u) return string(u)
} }