refactor: move CLI entry point to pkg/cli, remove cmd/
Consolidate CLI code into pkg/cli: - Add pkg/cli/app.go with Main() entry point and completionCmd - Move build variants to internal/variants/ (avoids import cycle) - Move i18n-validate tool to internal/tools/ - Update main.go to call cli.Main() - Remove cmd/ directory entirely Structure: - main.go imports internal/variants (triggers command registration) - main.go calls cli.Main() which runs the CLI - Build variants: go build, go build -tags ci/php/minimal Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
629141e279
commit
5b2c4eef75
9 changed files with 37 additions and 61 deletions
20
Taskfile.yml
20
Taskfile.yml
|
|
@ -1,12 +1,18 @@
|
|||
version: '3'
|
||||
|
||||
includes:
|
||||
gui: ./cmd/lthn-desktop/Taskfile.yml
|
||||
cli: ./cmd/core/Taskfile.yml
|
||||
demo: ./cmd/core-demo/Taskfile.yml
|
||||
ide: ./cmd/core-gui/Taskfile.yml
|
||||
|
||||
tasks:
|
||||
cli:build:
|
||||
desc: "Build the core CLI executable"
|
||||
cmds:
|
||||
- go build -o ./bin/core .
|
||||
|
||||
cli:run:
|
||||
desc: "Build and run the core CLI"
|
||||
cmds:
|
||||
- task: cli:build
|
||||
- ./bin/core {{.CLI_ARGS}}
|
||||
|
||||
|
||||
test:
|
||||
desc: "Run all Go tests recursively for the entire project."
|
||||
cmds:
|
||||
|
|
@ -53,4 +59,4 @@ tasks:
|
|||
i18n:validate:
|
||||
desc: "Validate i18n key usage across the codebase"
|
||||
cmds:
|
||||
- go run ./cmd/i18n-validate ./...
|
||||
- go run ./internal/tools/i18n-validate ./...
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
version: '3'
|
||||
|
||||
tasks:
|
||||
build:
|
||||
summary: Builds the core executable
|
||||
cmds:
|
||||
- go build -o {{.TASKFILE_DIR}}/../bin/core {{.TASKFILE_DIR}}/..
|
||||
|
||||
build:dev:
|
||||
summary: Builds and runs the core executable in development mode
|
||||
cmds:
|
||||
- go build -o {{.TASKFILE_DIR}}/../bin/core {{.TASKFILE_DIR}}/..
|
||||
- CORE_DEV_TOOLS="false" {{.TASKFILE_DIR}}/../bin/core
|
||||
8
main.go
8
main.go
|
|
@ -4,11 +4,15 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/host-uk/core/cmd"
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
|
||||
// Build variants import commands via self-registration.
|
||||
// See internal/variants/ for available variants: full, ci, php, minimal.
|
||||
_ "github.com/host-uk/core/internal/variants"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := cmd.Execute(); err != nil {
|
||||
if err := cli.Main(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,65 +1,44 @@
|
|||
// Package cmd implements the core CLI application.
|
||||
//
|
||||
// The CLI provides commands for:
|
||||
// - Multi-repo development workflows (dev)
|
||||
// - AI agent task management (ai)
|
||||
// - Go and PHP development tools (go, php)
|
||||
// - Build and release automation (build, ci)
|
||||
// - SDK validation and API compatibility (sdk)
|
||||
// - Package and environment management (pkg, vm)
|
||||
// - Documentation and testing (docs, test)
|
||||
// - Environment health checks (doctor)
|
||||
// - Repository setup and cloning (setup)
|
||||
//
|
||||
// Two build variants exist:
|
||||
// - Default build: Full development toolset
|
||||
// - CI build (-tags ci): Minimal release toolset
|
||||
package cmd
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/host-uk/core/pkg/cli"
|
||||
"github.com/host-uk/core/pkg/framework"
|
||||
"github.com/host-uk/core/pkg/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
// Build variants import commands via self-registration.
|
||||
// See cmd/variants/ for available variants: full, ci, php, minimal.
|
||||
_ "github.com/host-uk/core/cmd/variants"
|
||||
)
|
||||
|
||||
const (
|
||||
appName = "core"
|
||||
appVersion = "0.1.0"
|
||||
// AppName is the CLI application name.
|
||||
AppName = "core"
|
||||
// AppVersion is the CLI application version.
|
||||
AppVersion = "0.1.0"
|
||||
)
|
||||
|
||||
|
||||
|
||||
// Execute initialises and runs the CLI application.
|
||||
// Commands are registered based on build tags (see core_ci.go and core_dev.go).
|
||||
func Execute() error {
|
||||
// Main initialises and runs the CLI application.
|
||||
// This is the main entry point for the CLI.
|
||||
func Main() error {
|
||||
// Initialise CLI runtime with services
|
||||
if err := cli.Init(cli.Options{
|
||||
AppName: appName,
|
||||
Version: appVersion,
|
||||
if err := Init(Options{
|
||||
AppName: AppName,
|
||||
Version: AppVersion,
|
||||
Services: []framework.Option{
|
||||
framework.WithName("i18n", cli.NewI18nService(cli.I18nOptions{})),
|
||||
framework.WithName("log", cli.NewLogService(cli.LogOptions{
|
||||
Level: cli.LogLevelInfo,
|
||||
framework.WithName("i18n", NewI18nService(I18nOptions{})),
|
||||
framework.WithName("log", NewLogService(log.Options{
|
||||
Level: log.LevelInfo,
|
||||
})),
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
defer cli.Shutdown()
|
||||
defer Shutdown()
|
||||
|
||||
// Add completion command to the CLI's root
|
||||
cli.RootCmd().AddCommand(completionCmd)
|
||||
RootCmd().AddCommand(completionCmd)
|
||||
|
||||
return cli.Execute()
|
||||
return Execute()
|
||||
}
|
||||
|
||||
|
||||
// completionCmd generates shell completion scripts.
|
||||
var completionCmd = &cobra.Command{
|
||||
Use: "completion [bash|zsh|fish|powershell]",
|
||||
Loading…
Add table
Reference in a new issue