v0.19 β v0.20: deprecated setup middleware helpers removed¶
Two // Deprecated: middleware helpers in pkg/setup β deprecated since the
composed setup.Command type landed in v0.5 β are removed:
setup.AddCommandWithMiddleware(parent, child, feature)setup.ApplyMiddlewareRecursively(cmd, feature)
Both are superseded by the composed setup.Command wrapper, whose Register
method wires global and feature-specific middleware onto each child's RunE
exactly once at attach time.
What changed¶
// Before (removed)
setup.AddCommandWithMiddleware(rootCmd, serve.NewCmdServe(p), props.ServeCmd)
// After
parent := setup.Wrap("", rootCmd)
parent.Register(setup.Wrap(props.ServeCmd, serve.NewCmdServe(p)))
In practice, GTB command constructors already return *setup.Command carrying
their own feature key, so a parent simply does:
Register attaches each child and wraps it with its own feature. Unlike the
removed ApplyMiddlewareRecursively, it does not re-wrap a subtree with the
parent's feature β each command carries the middleware key it was constructed
with, and its descendants are wired when it registers them.
Impact¶
- Direct callers (build break): code calling either helper no longer
compiles. Replace
AddCommandWithMiddleware(parent, child, feature)withparent.Register(setup.Wrap(feature, child)). Code relying onApplyMiddlewareRecursivelyshould instead wrap each command with its own feature at construction (viasetup.Wrap) and attach it throughparent.Register. - Generated tools: none. The generator stopped emitting
AddCommandWithMiddlewarewhen the composedsetup.Commandtype landed; it has emittedparent.Register(...)(and the variadicNewCmdRoot(p, subsβ¦)form) ever since, and never emittedApplyMiddlewareRecursively. Regenerating an older project moves any residual call toRegister. regenerate manifest/remove command: the scanner and removal passes no longer recognise the legacyAddCommandWithMiddlewarecall form. Projects whosecmd.gostill contains it should rungtb regenerate project(or migrate the call by hand) so registrations are expressed viaRegisterbefore relying on manifest round-tripping.
How to migrate¶
- Replace every
setup.AddCommandWithMiddleware(parent, child, feature)withsetup.Wrap("", parent).Register(setup.Wrap(feature, child))β or, preferably, make the child constructor return*setup.Commandand callparent.Register(child). - Replace any
setup.ApplyMiddlewareRecursively(cmd, feature)usage by wrapping each command with its own feature at construction and registering subcommands viaparent.Register. - Regenerate scaffolded projects with
gtb regenerate projectso any remaining legacy registrations are rewritten toRegister.