fix(summer): delegate admin, route and key commands and pass all delegate flags through
- delegateCommands() builds every delegate from one table of name, description and common-flags hint; toolCommands appends it - route:list, key:generate, admin:create and admin:reset-password are new delegates; the child keeps summer's stdin, so the password prompts work - migrate:rollback, queue:work and schedule:run lose their hand-written flag copies: --plugin, --queue and --once now pass through verbatim - the command list marks delegates with "(flags pass to the app binary)" and the help command prints a Long text with the common flags - console introduction, setup-and-maintenance and the root README describe the passthrough behaviour and the new delegates
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/bonfire"
|
||||
@@ -42,3 +43,73 @@ func TestDelegatedServePassesFlags(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelegateCommandsPassArgs(t *testing.T) {
|
||||
for _, args := range [][]string{
|
||||
{"migrate:rollback", "--plugin", "acme.blog"},
|
||||
{"queue:work", "--queue", "a", "--queue", "b"},
|
||||
{"schedule:run", "--once"},
|
||||
{"queue:clear", "emails"},
|
||||
{"migrate"},
|
||||
{"migrate:status", "--help"},
|
||||
{"route:list"},
|
||||
{"key:generate"},
|
||||
{"admin:create", "--email", "you@example.com", "--superuser"},
|
||||
{"admin:reset-password", "admin@example.com"},
|
||||
} {
|
||||
got := captureAppRunner(t)
|
||||
if out, err := runSummer(t, args...); err != nil {
|
||||
t.Fatalf("%q: %v\n%s", args, err, out)
|
||||
}
|
||||
if !slices.Equal(*got, args) {
|
||||
t.Fatalf("%q: argv = %q, want %q", args, *got, args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelegateCommandsHelp(t *testing.T) {
|
||||
hints := map[string][]string{
|
||||
"migrate:rollback": {"--plugin"},
|
||||
"queue:work": {"--queue"},
|
||||
"schedule:run": {"--once"},
|
||||
"serve": {"--addr"},
|
||||
"admin:create": {"--email", "--superuser"},
|
||||
}
|
||||
cmds := delegateCommands()
|
||||
if len(cmds) != 11 {
|
||||
t.Fatalf("delegateCommands() has %d commands, want 11", len(cmds))
|
||||
}
|
||||
got := captureAppRunner(t)
|
||||
for _, c := range cmds {
|
||||
out, err := runSummer(t, "help", c.Name)
|
||||
if err != nil {
|
||||
t.Fatalf("help %s: %v", c.Name, err)
|
||||
}
|
||||
for _, want := range append([]string{"passed to the app binary"}, hints[c.Name]...) {
|
||||
if !strings.Contains(out, want) {
|
||||
t.Fatalf("help %s missing %q:\n%s", c.Name, want, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
if *got != nil {
|
||||
t.Fatalf("help ran the app binary with %q", *got)
|
||||
}
|
||||
|
||||
out, err := runSummer(t, "--help")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, c := range cmds {
|
||||
found := false
|
||||
for _, line := range strings.Split(out, "\n") {
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) > 0 && fields[0] == c.Name && strings.Contains(line, "(flags pass to the app binary)") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("summer --help does not mark %s:\n%s", c.Name, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user