fix(summer): pass delegated command flags to the app binary

- delegateCommand builds a Passthrough bonfire command, so
  `summer serve --addr :8123`, `summer serve --help` and `-h` reach the
  app binary instead of failing with "unknown flag: --addr"
- one leading "--" is dropped so `summer serve -- --addr :8123` still
  works
- appRunner is a package-level seam that tests replace to capture argv
This commit is contained in:
Jakub Zych
2026-10-08 15:50:03 +02:00
parent 14f6982c4d
commit 9eb2a9237c
2 changed files with 56 additions and 3 deletions

View File

@@ -13,14 +13,23 @@ import (
"git.golem15.com/golem15/summercms/modules/bonfire"
)
// appRunner runs the app binary with argv; tests replace it.
var appRunner = runAppBinary
func delegateCommand(name, description string) bonfire.Command {
return bonfire.Command{
Name: name,
Description: description,
Passthrough: true,
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
argv := []string{name}
argv = append(argv, in.Args()...)
return runAppBinary(ctx, argv, out)
args := in.Args()
// One leading "--" is dropped so the older
// `summer serve -- --addr :8123` form keeps working.
if len(args) > 0 && args[0] == "--" {
args = args[1:]
}
argv := append([]string{name}, args...)
return appRunner(ctx, argv, out)
},
}
}