Skip to content

Commit

Permalink
Use internal/expr
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Dec 30, 2024
1 parent 3da277a commit 200de2b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions book.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/goccy/go-json"
"github.com/goccy/go-yaml"
"github.com/k1LoW/duration"
"github.com/k1LoW/runn/internal/expr"
"github.com/k1LoW/sshc/v4"
)

Expand Down Expand Up @@ -130,7 +131,7 @@ func (bk *book) parseRunners(store map[string]any) error {
// parse SSH Runners first for port forwarding
var notSSHRunners []string
if store != nil {
r, err := EvalExpand(bk.runners, store)
r, err := expr.EvalExpand(bk.runners, store)
if err != nil {
return err
}
Expand Down Expand Up @@ -160,7 +161,7 @@ func (bk *book) parseRunners(store map[string]any) error {

func (bk *book) parseVars(store map[string]any) error {
if store != nil {
v, err := EvalExpand(bk.vars, store)
v, err := expr.EvalExpand(bk.vars, store)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion dbg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/elk-language/go-prompt"
pstrings "github.com/elk-language/go-prompt/strings"
"github.com/k0kubun/pp/v3"
"github.com/k1LoW/runn/internal/expr"
"github.com/k1LoW/runn/internal/store"
"github.com/olekukonko/tablewriter"
"github.com/samber/lo"
Expand Down Expand Up @@ -199,7 +200,7 @@ L:
if !s.deferred {
sm[store.RootKeyPrevious] = s.parent.store.Latest()
}
e, err := Eval(cmd[1], sm)
e, err := expr.Eval(cmd[1], sm)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%s\n", err.Error())
continue
Expand Down
3 changes: 2 additions & 1 deletion loadt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/dustin/go-humanize"
"github.com/k1LoW/runn/internal/expr"
or "github.com/ryo-yamaoka/otchkiss/result"
)

Expand Down Expand Up @@ -147,7 +148,7 @@ func (r *loadtResult) CheckThreshold(threshold string) error {
"p99": r.p99 * 1000,
"avg": r.avg * 1000,
}
tf, err := EvalWithTrace(threshold, store)
tf, err := expr.EvalWithTrace(threshold, store)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (op *operator) runStep(ctx context.Context, s *step) error {
bt string
j int
)
c, err := EvalCount(s.loop.Count, op.store.ToMap())
c, err := expr.EvalCount(s.loop.Count, op.store.ToMap())
if err != nil {
return err
}
Expand All @@ -352,7 +352,7 @@ func (op *operator) runStep(ctx context.Context, s *step) error {
sm[store.RootKeyPrevious] = op.store.Previous()
}
sm[store.RootKeyCurrent] = op.store.Latest()
tf, err := EvalWithTrace(s.loop.Until, sm)
tf, err := expr.EvalWithTrace(s.loop.Until, sm)
if err != nil {
return fmt.Errorf("loop failed on %s: %w", op.stepName(idx), err)
}
Expand Down Expand Up @@ -1058,7 +1058,7 @@ func (op *operator) runLoop(ctx context.Context) error {
bt string
j int
)
c, err := EvalCount(op.loop.Count, op.store.ToMap())
c, err := expr.EvalCount(op.loop.Count, op.store.ToMap())
if err != nil {
return err
}
Expand Down Expand Up @@ -1513,7 +1513,7 @@ func Load(pathp string, opts ...Option) (*operatorN, error) {
continue
}
// RUNN_LABEL, --label
tf, err := EvalCond(cond, labelEnv(op.labels))
tf, err := expr.EvalCond(cond, labelEnv(op.labels))
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/k1LoW/donegroup"
"github.com/k1LoW/httpstub"
"github.com/k1LoW/runn/internal/expr"
"github.com/k1LoW/runn/internal/store"
"github.com/k1LoW/runn/testutil"
"github.com/k1LoW/stopw"
Expand Down Expand Up @@ -1610,7 +1611,7 @@ func TestLabelCond(t *testing.T) {
for _, tt := range tests {
t.Run(fmt.Sprintf("%v", tt.runLabels), func(t *testing.T) {
cond := labelCond(tt.runLabels)
got, err := EvalCond(cond, labelEnv(tt.labels))
got, err := expr.EvalCond(cond, labelEnv(tt.labels))
if err != nil {
t.Error(err)
}
Expand Down
3 changes: 2 additions & 1 deletion option.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
pstrings "github.com/elk-language/go-prompt/strings"
"github.com/k1LoW/duration"
"github.com/k1LoW/runn/builtin"
"github.com/k1LoW/runn/internal/expr"
"github.com/k1LoW/runn/internal/store"
"github.com/k1LoW/sshc/v4"
"github.com/samber/lo"
Expand Down Expand Up @@ -1033,7 +1034,7 @@ func AfterFuncIf(fn func(*RunResult) error, ifCond string) Option {
return ErrNilBook
}
bk.afterFuncs = append(bk.afterFuncs, func(r *RunResult) error {
tf, err := EvalCond(ifCond, r.Store())
tf, err := expr.EvalCond(ifCond, r.Store())
if err != nil {
return err
}
Expand Down

0 comments on commit 200de2b

Please sign in to comment.