lib: Change test/modules registration mechanism.

Previously modules registration and usage looked like this:

func foo(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
...
}

func init() {
modules.RegisterChild("foo", "", foo)
}

func TestFoo(t *testing.T) {
sh, err := modules.NewShell(...)
h, err := sh.Start("foo", nil, ...)
...
}

The new modules registration and usage looks like this:

var foo = modules.Register(func(env *modules.Env, args ...string) error {
...
}, "foo")

func TestFoo(t *testing.T) {
sh, err := modules.NewShell(...)
h, err := sh.Start(nil, foo, ...)
...
}

The main change is that Register now returns a modules.Program,
which is typically captured in a global variable, and is used as
the argument to Shell.Start.  This makes it easy to write the
registration manually, and we also have a more obvious linkage
between program registration and the Start call through the
program variable, rather than using strings.

Since registration was annoying to write manually, we used to
have 'v23 test generate' detect the functions and automatically
add the modules.RegisterChild call.  With the new mechanism, the
registration is simple to write manually, so 'v23 test generate'
has been simplified to remove the detection logic.

In fact the Program returned by modules.Register now must be
captured, so that it can be passed to Shell.Start; this forces
the linkage between Register and Start to be obvious.

Also removed the modules Help mechanism, since it wasn't being
used, and has questionable utility.  In its place, added logic to
dump all registered programs when program lookups fail.

MultiPart: 2/5

Change-Id: I6d97bc3bc0b74003fb875231ea47a40216a3bac5
2 files changed
tree: 06edfe3b84f6b36ff8ba652bd9f886ed74d2b263
  1. buildinfo/
  2. cmdline/
  3. dbutil/
  4. envvar/
  5. host/
  6. metadata/
  7. netconfig/
  8. netstate/
  9. pubsub/
  10. textutil/
  11. toposort/
  12. vlog/
  13. .gitignore
  14. AUTHORS
  15. CONTRIBUTORS
  16. GO.PACKAGE
  17. LICENSE
  18. PATENTS
  19. README.md
  20. VERSION
README.md

This repository contains general purpose libraries used by the Vanadium project.