refactor: register commands through Core framework lifecycle
Replace init() + cli.RegisterCommands() with cli.WithCommands() passed to cli.Main(). Commands now register as framework services and receive the root command during OnStartup — no global state, no blank imports. Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
800bb91601
commit
7303ba6f23
10 changed files with 20 additions and 42 deletions
|
|
@ -2,10 +2,6 @@ package config
|
|||
|
||||
import "forge.lthn.ai/core/go/pkg/cli"
|
||||
|
||||
func init() {
|
||||
cli.RegisterCommands(AddConfigCommands)
|
||||
}
|
||||
|
||||
// AddConfigCommands registers the 'config' command group and all subcommands.
|
||||
func AddConfigCommands(root *cli.Command) {
|
||||
configCmd := cli.NewGroup("config", "Manage configuration", "")
|
||||
|
|
|
|||
|
|
@ -10,14 +10,7 @@
|
|||
// Provides platform-specific installation instructions for missing tools.
|
||||
package doctor
|
||||
|
||||
import (
|
||||
"forge.lthn.ai/core/go/pkg/cli"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cli.RegisterCommands(AddDoctorCommands)
|
||||
}
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
// AddDoctorCommands registers the 'doctor' command and all subcommands.
|
||||
func AddDoctorCommands(root *cobra.Command) {
|
||||
|
|
|
|||
|
|
@ -7,10 +7,6 @@ import (
|
|||
"forge.lthn.ai/core/go/pkg/help"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cli.RegisterCommands(AddHelpCommands)
|
||||
}
|
||||
|
||||
func AddHelpCommands(root *cli.Command) {
|
||||
var searchFlag string
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,6 @@ import (
|
|||
"forge.lthn.ai/core/go/pkg/store"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cli.RegisterCommands(AddModuleCommands)
|
||||
}
|
||||
|
||||
// AddModuleCommands registers the 'module' command and all subcommands.
|
||||
func AddModuleCommands(root *cli.Command) {
|
||||
moduleCmd := &cli.Command{
|
||||
|
|
|
|||
|
|
@ -7,10 +7,6 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cli.RegisterCommands(AddPkgCommands)
|
||||
}
|
||||
|
||||
// Style and utility aliases
|
||||
var (
|
||||
repoNameStyle = cli.RepoStyle
|
||||
|
|
|
|||
|
|
@ -13,10 +13,6 @@ import (
|
|||
"forge.lthn.ai/core/go/pkg/i18n"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cli.RegisterCommands(AddPluginCommands)
|
||||
}
|
||||
|
||||
// AddPluginCommands registers the 'plugin' command and all subcommands.
|
||||
func AddPluginCommands(root *cli.Command) {
|
||||
pluginCmd := &cli.Command{
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ import (
|
|||
"forge.lthn.ai/core/go/pkg/session"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cli.RegisterCommands(AddSessionCommands)
|
||||
}
|
||||
|
||||
// AddSessionCommands registers the 'session' command group.
|
||||
func AddSessionCommands(root *cli.Command) {
|
||||
sessionCmd := &cli.Command{
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -3,7 +3,7 @@ module forge.lthn.ai/core/cli
|
|||
go 1.26.0
|
||||
|
||||
require (
|
||||
forge.lthn.ai/core/go v0.0.0-20260221191103-d091fa62023f
|
||||
forge.lthn.ai/core/go v0.0.0-20260221220640-2a90ae65b7c7
|
||||
forge.lthn.ai/core/go-crypt v0.0.0-20260221193816-fde12e1539b2 // indirect
|
||||
)
|
||||
|
||||
|
|
|
|||
2
go.sum
2
go.sum
|
|
@ -1,5 +1,7 @@
|
|||
forge.lthn.ai/core/go v0.0.0-20260221191103-d091fa62023f h1:CcSh/FFY93K5m0vADHLxwxKn2pTIM8HzYX1eGa4WZf4=
|
||||
forge.lthn.ai/core/go v0.0.0-20260221191103-d091fa62023f/go.mod h1:WCPJVEZm/6mTcJimHV0uX8ZhnKEF3dN0rQp13ByaSPg=
|
||||
forge.lthn.ai/core/go v0.0.0-20260221220640-2a90ae65b7c7 h1:UhlJo4QeqKD0IM0wKjOh8H3OaDnvdl5m7psozRXJdO8=
|
||||
forge.lthn.ai/core/go v0.0.0-20260221220640-2a90ae65b7c7/go.mod h1:WCPJVEZm/6mTcJimHV0uX8ZhnKEF3dN0rQp13ByaSPg=
|
||||
forge.lthn.ai/core/go-crypt v0.0.0-20260221193816-fde12e1539b2 h1:2eXqQXF+1AyitPJox9Yjewb6w8fO0JHFw7gPqk8WqIM=
|
||||
forge.lthn.ai/core/go-crypt v0.0.0-20260221193816-fde12e1539b2/go.mod h1:o4vkJgoT9u+r7DR42LIJHW6L5vMS3Au8gaaCA5Cved0=
|
||||
github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=
|
||||
|
|
|
|||
25
main.go
25
main.go
|
|
@ -1,17 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"forge.lthn.ai/core/cli/cmd/config"
|
||||
"forge.lthn.ai/core/cli/cmd/doctor"
|
||||
"forge.lthn.ai/core/cli/cmd/help"
|
||||
"forge.lthn.ai/core/cli/cmd/module"
|
||||
"forge.lthn.ai/core/cli/cmd/pkgcmd"
|
||||
"forge.lthn.ai/core/cli/cmd/plugin"
|
||||
"forge.lthn.ai/core/cli/cmd/session"
|
||||
"forge.lthn.ai/core/go/pkg/cli"
|
||||
|
||||
_ "forge.lthn.ai/core/cli/cmd/config"
|
||||
_ "forge.lthn.ai/core/cli/cmd/doctor"
|
||||
_ "forge.lthn.ai/core/cli/cmd/help"
|
||||
_ "forge.lthn.ai/core/cli/cmd/module"
|
||||
_ "forge.lthn.ai/core/cli/cmd/pkgcmd"
|
||||
_ "forge.lthn.ai/core/cli/cmd/plugin"
|
||||
_ "forge.lthn.ai/core/cli/cmd/session"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cli.Main()
|
||||
cli.Main(
|
||||
cli.WithCommands("config", config.AddConfigCommands),
|
||||
cli.WithCommands("doctor", doctor.AddDoctorCommands),
|
||||
cli.WithCommands("help", help.AddHelpCommands),
|
||||
cli.WithCommands("module", module.AddModuleCommands),
|
||||
cli.WithCommands("pkg", pkgcmd.AddPkgCommands),
|
||||
cli.WithCommands("plugin", plugin.AddPluginCommands),
|
||||
cli.WithCommands("session", session.AddSessionCommands),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue