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

View File

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

View File

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