diff --git a/.gitignore b/.gitignore index 70000de..e322e05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +bin/ /vendor /packages/*/vendor composer.lock diff --git a/bin/core-php b/bin/core-php deleted file mode 100755 index 5865552..0000000 Binary files a/bin/core-php and /dev/null differ diff --git a/cmd.go b/cmd.go index 14bcd4b..3de3c63 100644 --- a/cmd.go +++ b/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) + } +} diff --git a/cmd/core-php/main.go b/cmd/core-php/main.go index 7ea6c45..fb08c80 100644 --- a/cmd/core-php/main.go +++ b/cmd/core-php/main.go @@ -10,6 +10,6 @@ import ( func main() { cli.Main( - cli.WithCommands("php", php.AddPHPCommands), + cli.WithCommands("php", php.AddPHPRootCommands), ) }