Skip to content

Commit

Permalink
Merge pull request #23 from fujiwara/publish-funcs
Browse files Browse the repository at this point in the history
Publish functions ModifyValue and WithUpdate.
  • Loading branch information
aereal committed Dec 31, 2022
2 parents 3689e59 + eb9aae8 commit 2e79707
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ func Diff(from, to *Input, opts ...Option) (string, error) {
switch {
case o.ignore != nil:
var err error
q := withUpdate(o.ignore)
fromObj, err = modifyValue(q, fromObj)
q := WithUpdate(o.ignore)
fromObj, err = ModifyValue(q, fromObj)
if err != nil {
return "", fmt.Errorf("modify(lhs): %v", err)
}
toObj, err = modifyValue(q, toObj)
toObj, err = ModifyValue(q, toObj)
if err != nil {
return "", fmt.Errorf("modify(rhs): %v", err)
}
case o.only != nil:
var err error
fromObj, err = modifyValue(o.only, fromObj)
fromObj, err = ModifyValue(o.only, fromObj)
if err != nil {
return "", fmt.Errorf("modify(lhs): %v", err)
}
toObj, err = modifyValue(o.only, toObj)
toObj, err = ModifyValue(o.only, toObj)
if err != nil {
return "", fmt.Errorf("modify(lhs): %v", err)
}
Expand All @@ -136,7 +136,7 @@ func Diff(from, to *Input, opts ...Option) (string, error) {
return fmt.Sprint(d), nil
}

func modifyValue(query *gojq.Query, x interface{}) (interface{}, error) {
func ModifyValue(query *gojq.Query, x interface{}) (interface{}, error) {
iter := query.Run(x)
var ret interface{}
for {
Expand All @@ -163,7 +163,7 @@ func toJSON(x interface{}) (string, error) {
return b.String(), nil
}

func withUpdate(query *gojq.Query) *gojq.Query {
func WithUpdate(query *gojq.Query) *gojq.Query {
var ret *gojq.Query
qs := splitIntoTerms(query)
for j := len(qs) - 1; j >= 0; j-- {
Expand Down
2 changes: 1 addition & 1 deletion diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func Test_withUpdate(t *testing.T) {
for _, c := range queries {
t.Run(c.query, func(t *testing.T) {
want := parseQuery(t, c.want)
got := withUpdate(parseQuery(t, c.query))
got := WithUpdate(parseQuery(t, c.query))
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("-want, +got:\n%s", diff)
}
Expand Down

0 comments on commit 2e79707

Please sign in to comment.