* feat(help): Add CLI help command Fixes #136 * chore: remove binary * feat(mcp): Add TCP transport Fixes #126 * feat(io): Migrate pkg/mcp to use Medium abstraction Fixes #103 * chore(io): Migrate internal/cmd/docs/* to Medium abstraction Fixes #113 * chore(io): Migrate internal/cmd/dev/* to Medium abstraction Fixes #114 * chore(io): Migrate internal/cmd/setup/* to Medium abstraction * chore(io): Complete migration of internal/cmd/dev/* to Medium abstraction * chore(io): Migrate internal/cmd/sdk, pkgcmd, and workspace to Medium abstraction * style: fix formatting in internal/variants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor(io): simplify local Medium implementation Rewrote to match the simpler TypeScript pattern: - path() sanitizes and returns string directly - Each method calls path() once - No complex symlink validation - Less code, less attack surface Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test(mcp): update sandboxing tests for simplified Medium The simplified io/local.Medium implementation: - Sanitizes .. to . (no error, path is cleaned) - Allows absolute paths through (caller validates if needed) - Follows symlinks (no traversal blocking) Update tests to match this simplified behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(updater): resolve PkgVersion duplicate declaration Remove var PkgVersion from updater.go since go generate creates const PkgVersion in version.go. Track version.go in git to ensure builds work without running go generate first. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package generators
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
|
|
coreio "github.com/host-uk/core/pkg/io"
|
|
)
|
|
|
|
// PHPGenerator generates PHP SDKs from OpenAPI specs.
|
|
type PHPGenerator struct{}
|
|
|
|
// NewPHPGenerator creates a new PHP generator.
|
|
func NewPHPGenerator() *PHPGenerator {
|
|
return &PHPGenerator{}
|
|
}
|
|
|
|
// Language returns the generator's target language identifier.
|
|
func (g *PHPGenerator) Language() string {
|
|
return "php"
|
|
}
|
|
|
|
// Available checks if generator dependencies are installed.
|
|
func (g *PHPGenerator) Available() bool {
|
|
_, err := exec.LookPath("docker")
|
|
return err == nil
|
|
}
|
|
|
|
// Install returns instructions for installing the generator.
|
|
func (g *PHPGenerator) Install() string {
|
|
return "Docker is required for PHP SDK generation"
|
|
}
|
|
|
|
// Generate creates SDK from OpenAPI spec.
|
|
func (g *PHPGenerator) Generate(ctx context.Context, opts Options) error {
|
|
if !g.Available() {
|
|
return fmt.Errorf("php.Generate: Docker is required but not available")
|
|
}
|
|
|
|
if err := coreio.Local.EnsureDir(opts.OutputDir); err != nil {
|
|
return fmt.Errorf("php.Generate: failed to create output dir: %w", err)
|
|
}
|
|
|
|
specDir := filepath.Dir(opts.SpecPath)
|
|
specName := filepath.Base(opts.SpecPath)
|
|
|
|
args := []string{"run", "--rm"}
|
|
args = append(args, dockerUserArgs()...)
|
|
args = append(args,
|
|
"-v", specDir+":/spec",
|
|
"-v", opts.OutputDir+":/out",
|
|
"openapitools/openapi-generator-cli", "generate",
|
|
"-i", "/spec/"+specName,
|
|
"-g", "php",
|
|
"-o", "/out",
|
|
"--additional-properties=invokerPackage="+opts.PackageName,
|
|
)
|
|
|
|
cmd := exec.CommandContext(ctx, "docker", args...)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
|
|
if err := cmd.Run(); err != nil {
|
|
return fmt.Errorf("php.Generate: %w", err)
|
|
}
|
|
return nil
|
|
}
|