Skip to content

Commit

Permalink
Add a -max flag to limit the number of evaluations.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisberkhout committed Feb 12, 2024
1 parent 989f294 commit abba66f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mito.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func Main() int {
}
use := flag.String("use", "all", "libraries to use")
data := flag.String("data", "", "path to a JSON object holding input (exposed as the label "+root+")")
max := flag.Uint("max", 1000000, "maximum number of evaluations")
cfgPath := flag.String("cfg", "", "path to a YAML file holding configuration for global vars and regular expressions")
insecure := flag.Bool("insecure", false, "disable TLS verification in the HTTP client")
version := flag.Bool("version", false, "print version and exit")
Expand Down Expand Up @@ -183,7 +184,7 @@ func Main() int {
input = map[string]interface{}{root: input}
}

for {
for n := uint(0); n < *max; n++ {
res, val, err := eval(string(b), root, input, libs...)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Expand Down
20 changes: 20 additions & 0 deletions testdata/want_more_max.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
mito -data state.json -max 2 src.cel
! stderr .
cmp stdout want.txt

-- state.json --
{"n": 0}
-- src.cel --
int(state.n).as(n, {
"n": n+1,
"want_more": n+1 < 5,
})
-- want.txt --
{
"n": 1,
"want_more": true
}
{
"n": 2,
"want_more": true
}

0 comments on commit abba66f

Please sign in to comment.