refactor(10.2-01): nest framework packages under modules
- Move remaining beach packages and embedded admin assets\n- Rewrite framework, example, build, and gate paths
This commit is contained in:
39
modules/surf/routelist_command.go
Normal file
39
modules/surf/routelist_command.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package surf
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/bonfire"
|
||||
"git.golem15.com/golem15/summercms/modules/party"
|
||||
)
|
||||
|
||||
// RouteListCommand builds the router the same way ServeCommand does, then
|
||||
// renders Routes() as a table instead of serving.
|
||||
func RouteListCommand(app *backpack.App, plugins []party.Plugin) bonfire.Command {
|
||||
return bonfire.Command{
|
||||
Name: "route:list",
|
||||
Description: "List registered HTTP routes",
|
||||
Run: func(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
||||
r, err := BuildRouter(app, plugins)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
infos := r.Routes()
|
||||
rows := make([][]string, 0, len(infos))
|
||||
for _, rt := range infos {
|
||||
rows = append(rows, []string{
|
||||
rt.Method,
|
||||
rt.Pattern,
|
||||
rt.PluginID,
|
||||
strings.Join(rt.Middleware, ","),
|
||||
strconv.FormatBool(rt.Raw),
|
||||
})
|
||||
}
|
||||
out.Table([]string{"Method", "Pattern", "Plugin", "Middleware", "Raw"}, rows)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user