feat: promote PHP commands to root in core-php binary
AddPHPRootCommands registers commands directly on root so the standalone binary uses `core-php dev` not `core-php php dev`. AddPHPCommands remains for use inside the `core` CLI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4b24a6d186
commit
dc064cbb61
4 changed files with 62 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
bin/
|
||||
/vendor
|
||||
/packages/*/vendor
|
||||
composer.lock
|
||||
|
|
|
|||
BIN
bin/core-php
BIN
bin/core-php
Binary file not shown.
60
cmd.go
60
cmd.go
|
|
@ -134,3 +134,63 @@ func AddPHPCommands(root *cli.Command) {
|
|||
|
||||
// registerFrankenPHP is set by cmd_serve_frankenphp.go when CGO is enabled.
|
||||
var registerFrankenPHP func(phpCmd *cli.Command)
|
||||
|
||||
// AddPHPRootCommands adds PHP commands directly to root (for standalone core-php binary).
|
||||
func AddPHPRootCommands(root *cli.Command) {
|
||||
root.PersistentPreRunE = func(cmd *cli.Command, args []string) error {
|
||||
wsRoot, err := findWorkspaceRoot()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
config, err := loadWorkspaceConfig(wsRoot)
|
||||
if err != nil || config == nil {
|
||||
return nil
|
||||
}
|
||||
if config.Active == "" {
|
||||
return nil
|
||||
}
|
||||
pkgDir := config.PackagesDir
|
||||
if pkgDir == "" {
|
||||
pkgDir = "./packages"
|
||||
}
|
||||
if !filepath.IsAbs(pkgDir) {
|
||||
pkgDir = filepath.Join(wsRoot, pkgDir)
|
||||
}
|
||||
targetDir := filepath.Join(pkgDir, config.Active)
|
||||
if !getMedium().IsDir(targetDir) {
|
||||
cli.Warnf("Active package directory not found: %s", targetDir)
|
||||
return nil
|
||||
}
|
||||
if err := os.Chdir(targetDir); err != nil {
|
||||
return cli.Err("failed to change directory to active package: %w", err)
|
||||
}
|
||||
cli.Print("%s %s\n", dimStyle.Render("Workspace:"), config.Active)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Development
|
||||
addPHPDevCommand(root)
|
||||
addPHPLogsCommand(root)
|
||||
addPHPStopCommand(root)
|
||||
addPHPStatusCommand(root)
|
||||
addPHPSSLCommand(root)
|
||||
|
||||
// Build & Deploy
|
||||
addPHPBuildCommand(root)
|
||||
addPHPServeCommand(root)
|
||||
addPHPShellCommand(root)
|
||||
|
||||
// CI/CD Integration
|
||||
addPHPCICommand(root)
|
||||
|
||||
// Package Management
|
||||
addPHPPackagesCommands(root)
|
||||
|
||||
// Deployment
|
||||
addPHPDeployCommands(root)
|
||||
|
||||
// FrankenPHP embedded commands (CGO only)
|
||||
if registerFrankenPHP != nil {
|
||||
registerFrankenPHP(root)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@ import (
|
|||
|
||||
func main() {
|
||||
cli.Main(
|
||||
cli.WithCommands("php", php.AddPHPCommands),
|
||||
cli.WithCommands("php", php.AddPHPRootCommands),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue