feat: add files() function

also add files-find-lang and files-find-doc helpers
This commit is contained in:
2025-01-24 19:23:41 +03:00
parent b5bf6ab61d
commit f6ba4a1c26
8 changed files with 523 additions and 64 deletions

View File

@ -177,7 +177,35 @@ func (d *Decoder) GetFunc(name string) (ScriptFunc, bool) {
return func(ctx context.Context, opts ...interp.RunnerOption) error {
sub := d.Runner.Subshell()
for _, opt := range opts {
opt(sub)
err := opt(sub)
if err != nil {
return err
}
}
return sub.Run(ctx, fn)
}, true
}
type PrepareFunc func(context.Context, *interp.Runner) error
func (d *Decoder) GetFuncP(name string, prepare PrepareFunc) (ScriptFunc, bool) {
fn := d.getFunc(name)
if fn == nil {
return nil, false
}
return func(ctx context.Context, opts ...interp.RunnerOption) error {
sub := d.Runner.Subshell()
for _, opt := range opts {
err := opt(sub)
if err != nil {
return err
}
}
if prepare != nil {
if err := prepare(ctx, sub); err != nil {
return err
}
}
return sub.Run(ctx, fn)
}, true