Skip to content

Commit

Permalink
Merge pull request #24 from mindstand/cli_patch
Browse files Browse the repository at this point in the history
Cli patch
  • Loading branch information
nikitawootten authored Dec 6, 2019
2 parents 1d47505 + b828f2a commit e146988
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 87 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ jobs:
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Setup gogmcli test
run: |
export ROOTDIR=`pwd`
rm testing_/linking.go
cd cmd/gogmcli
go build .
mv gogmcli $ROOTDIR/testing_/gogmcli
cd $ROOTDIR/testing_
./gogmcli gen .
cd $ROOTDIR
- name: Build
run: go build -v .
- name: Run Unit Tests
Expand Down
7 changes: 4 additions & 3 deletions cmd/gogmcli/gen/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"errors"
go_cypherdsl "github.com/mindstand/go-cypherdsl"
"github.com/mindstand/gogm/cmd/gogmcli/util"
"go/ast"
"go/parser"
"go/printer"
Expand Down Expand Up @@ -185,15 +186,15 @@ func parseGogmNode(strType *ast.StructType, confs *map[string][]*relConf, label
if !strings.Contains(part, "gogm") {
continue
}
part = strings.Replace(strings.Replace(part, "`gogm:", "", -1), "\"", "", -1)
part = util.RemoveFromString(part, "gogm:", "\"", "`")
if strings.Contains(part, "relationship") && strings.Contains(part, "direction") {
gogmParts := strings.Split(part, ";")

var dir go_cypherdsl.Direction
var relName string
for _, p := range gogmParts {
if strings.Contains(p, "direction") {
str := strings.ToLower(strings.Replace(strings.Replace(strings.Replace(p, "direction=", "", -1), "\"", "", -1), "`", "", -1))
str := util.RemoveFromString(p, "direction=", "\"")
switch str {
case "incoming":
dir = go_cypherdsl.DirectionIncoming
Expand All @@ -212,7 +213,7 @@ func parseGogmNode(strType *ast.StructType, confs *map[string][]*relConf, label
continue fieldLoop
}
} else if strings.Contains(part, "relationship") {
relName = strings.ToLower(strings.Replace(strings.Replace(p, "relationship=", "", -1), "\"", "", -1))
relName = strings.ToLower(util.RemoveFromString(p, "relationship=", "\"", "`"))
}
}

Expand Down
10 changes: 10 additions & 0 deletions cmd/gogmcli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package util

import "strings"

// RemoveDuplicates removes duplicates from string slice
func RemoveDuplicates(s []string) []string {
if s == nil {
Expand All @@ -38,6 +40,14 @@ func RemoveDuplicates(s []string) []string {
return s[:j]
}

func RemoveFromString(original string, removals ...string) string {
for _, r := range removals {
original = strings.Replace(original, r, "", -1)
}

return original
}

func StringSliceContains(s []string, e string) bool {
for _, a := range s {
if a == e {
Expand Down
166 changes: 83 additions & 83 deletions testing_/linking.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion testing_/test_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import "github.com/mindstand/gogm"
type ExampleObject struct {
gogm.BaseNode

Children []*ExampleObject `gogm:"direction=incoming;relationship=test" json:"children"`
Children []*ExampleObject `json:"children" gogm:"direction=incoming;relationship=test"`
Parents *ExampleObject `gogm:"direction=outgoing;relationship=test" json:"parents"`
Special *SpecialEdge `gogm:"direction=incoming;relationship=special" json:"special"`
}

0 comments on commit e146988

Please sign in to comment.