Skip to content

Commit 3fe1681

Browse files
committed
feat: add "lockjson/write" function
1 parent e74aa10 commit 3fe1681

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

dsl/ops/func_lockjson_write.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package ops
2+
3+
import (
4+
"context"
5+
6+
"github.com/pkg/errors"
7+
"github.com/vim-volt/volt/dsl/dslctx"
8+
"github.com/vim-volt/volt/dsl/ops/util"
9+
"github.com/vim-volt/volt/dsl/types"
10+
"github.com/vim-volt/volt/lockjson"
11+
)
12+
13+
func init() {
14+
opsMap["lockjson/write"] = LockJSONWriteOp
15+
}
16+
17+
type lockJSONWriteOp struct {
18+
funcBase
19+
}
20+
21+
// LockJSONWriteOp is "lockjson/write" operator
22+
var LockJSONWriteOp = &lockJSONWriteOp{funcBase("lockjson/write")}
23+
24+
func (*lockJSONWriteOp) Bind(args ...types.Value) (types.Expr, error) {
25+
if err := util.Signature().Check(args); err != nil {
26+
return nil, err
27+
}
28+
retType := types.VoidType
29+
return types.NewExpr(LockJSONWriteOp, args, retType), nil
30+
}
31+
32+
func (*lockJSONWriteOp) InvertExpr(args []types.Value) (types.Value, error) {
33+
return LockJSONWriteOp.Bind(args...)
34+
}
35+
36+
func (*lockJSONWriteOp) EvalExpr(ctx context.Context, args []types.Value) (_ types.Value, rollback func(), result error) {
37+
rollback = NoRollback
38+
39+
lockJSON := ctx.Value(dslctx.LockJSONKey).(*lockjson.LockJSON)
40+
result = lockJSON.Write()
41+
if result != nil {
42+
result = errors.Wrap(result, "could not write to lock.json")
43+
}
44+
45+
return
46+
}

0 commit comments

Comments
 (0)