wand exec fixes
This commit is contained in:
parent
e5ef043d2c
commit
7e5e7e97f8
@ -50,7 +50,7 @@ docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.NoC
|
|||||||
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.PurgeCache", "")
|
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.ExecOptions.PurgeCache", "")
|
||||||
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Man", "\nfunc(out, commandDir)")
|
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Man", "\nfunc(out, commandDir)")
|
||||||
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Markdown", "\nfunc(out, commandDir)")
|
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.Markdown", "\nfunc(out, commandDir)")
|
||||||
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.copyGomod", "\nfunc(fn, dst, src)")
|
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.copyGomod", "\nfunc(mn, dst, src)")
|
||||||
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execCommandDir", "\nfunc(out, commandDir, env)")
|
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execCommandDir", "\nfunc(out, commandDir, env)")
|
||||||
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execInternal", "\nfunc(command, args)")
|
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execInternal", "\nfunc(command, args)")
|
||||||
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execTransparent", "\nfunc(command, args)")
|
docreflect.Register("code.squareroundforest.org/arpio/wand/tools.execTransparent", "\nfunc(command, args)")
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
fix go.mod file path in exec
|
speed up wand exec with smarter caching
|
||||||
test starting from the most referenced file to the least referenced one
|
test starting from the most referenced file to the least referenced one
|
||||||
run only the related test when testing a file
|
run only the related test when testing a file
|
||||||
|
fix notation: .build/wand net/http.Get https://squareroundforest.org | less
|
||||||
|
fix wand exec: .build/wand -- 'func(a struct{Foo string}) string { return a.Foo }' --foo bar
|
||||||
|
allow in wand exec: .build/wand 'regexp.MustCompile("a").MatchString' aaa
|
||||||
|
considering that the possible input comes from limited sources, it may make sense to not escape just every dot in markdown
|
||||||
|
|
||||||
reflect
|
reflect
|
||||||
command
|
command
|
||||||
|
|||||||
@ -27,6 +27,8 @@ func printOutput(w io.Writer, o []any) error {
|
|||||||
if _, err := fmt.Fprintln(w, oi); err != nil {
|
if _, err := fmt.Fprintln(w, oi); err != nil {
|
||||||
return wraperr(err)
|
return wraperr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
t = unpack(t, reflect.Pointer)
|
t = unpack(t, reflect.Pointer)
|
||||||
|
|||||||
@ -80,8 +80,8 @@ func splitFunction(function string) (pkg string, expression string, err error) {
|
|||||||
if len(sparts) == 1 {
|
if len(sparts) == 1 {
|
||||||
expression = sparts[0]
|
expression = sparts[0]
|
||||||
} else {
|
} else {
|
||||||
pkg = strings.Join(append(gopath, sparts[0]), "/")
|
|
||||||
expression = parts[len(parts)-1]
|
expression = parts[len(parts)-1]
|
||||||
|
pkg = strings.Join(append(gopath, sparts[0]), "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -91,7 +91,7 @@ func functionHash(function string) (string, error) {
|
|||||||
h := fnv.New128()
|
h := fnv.New128()
|
||||||
h.Write([]byte(function))
|
h.Write([]byte(function))
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
b64 := base64.NewEncoder(base64.URLEncoding, buf)
|
b64 := base64.NewEncoder(base64.RawURLEncoding, buf)
|
||||||
if _, err := b64.Write(h.Sum(nil)); err != nil {
|
if _, err := b64.Write(h.Sum(nil)); err != nil {
|
||||||
return "", fmt.Errorf("failed to encode function: %w", err)
|
return "", fmt.Errorf("failed to encode function: %w", err)
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ func functionHash(function string) (string, error) {
|
|||||||
return "", fmt.Errorf("failed to complete encoding of function: %w", err)
|
return "", fmt.Errorf("failed to complete encoding of function: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.String(), nil
|
return strings.TrimPrefix(buf.String(), "_"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findGomod(wd string) (string, bool) {
|
func findGomod(wd string) (string, bool) {
|
||||||
@ -120,7 +120,7 @@ func findGomod(wd string) (string, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyGomod(fn, dst, src string) error {
|
func copyGomod(mn, dst, src string) error {
|
||||||
srcf, err := os.Open(src)
|
srcf, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open file: %s; %w", src, err)
|
return fmt.Errorf("failed to open file: %s; %w", src, err)
|
||||||
@ -142,7 +142,7 @@ func copyGomod(fn, dst, src string) error {
|
|||||||
ss := strings.Split(s, "\n")
|
ss := strings.Split(s, "\n")
|
||||||
for i := range ss {
|
for i := range ss {
|
||||||
if strings.HasPrefix(ss[i], "module ") {
|
if strings.HasPrefix(ss[i], "module ") {
|
||||||
ss[i] = fmt.Sprintf("module %s", fn)
|
ss[i] = fmt.Sprintf("module %s", mn)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +218,6 @@ func Exec(o ExecOptions, function string, args ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
goGet := func(pkg string) error {
|
goGet := func(pkg string) error {
|
||||||
println("go get", pkg)
|
|
||||||
if err := execInternal("go get", pkg); err != nil {
|
if err := execInternal("go get", pkg); err != nil {
|
||||||
return fmt.Errorf("failed to get go module: %w", err)
|
return fmt.Errorf("failed to get go module: %w", err)
|
||||||
}
|
}
|
||||||
@ -233,7 +232,7 @@ func Exec(o ExecOptions, function string, args ...string) error {
|
|||||||
defer os.Chdir(wd)
|
defer os.Chdir(wd)
|
||||||
gomodPath, hasGomod := findGomod(wd)
|
gomodPath, hasGomod := findGomod(wd)
|
||||||
if hasGomod {
|
if hasGomod {
|
||||||
if err := copyGomod(expression, path.Join(functionDir, "go.mod"), gomodPath); err != nil {
|
if err := copyGomod(functionHash, path.Join(functionDir, "go.mod"), gomodPath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -242,7 +241,8 @@ func Exec(o ExecOptions, function string, args ...string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pkg != "" {
|
// non-robust way of avoiding importing standard library packages:
|
||||||
|
if strings.Contains(pkg, ".") {
|
||||||
if err := goGet(pkg); err != nil {
|
if err := goGet(pkg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user