refactor(cli): restructure cmd packages into subdirectories
- Move CLI commands into subdirectories matching command hierarchy:
dev/, go/, php/, build/, ci/, sdk/, pkg/, vm/, docs/, setup/, doctor/, test/, ai/
- Create shared/ package for common styles and utilities
- Add new `core ai` root command with claude subcommand
- Update package declarations and imports across all files
- Create commands.go entry points for each package
- Remove GUI-related files (moved to core-gui repo)
This makes the filesystem structure match the CLI command structure,
improving context capture and code organization.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:02:43 +00:00
|
|
|
// Package sdk provides SDK validation and API compatibility commands.
|
|
|
|
|
package sdk
|
2026-01-29 01:22:40 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/charmbracelet/lipgloss"
|
refactor(cli): restructure cmd packages into subdirectories
- Move CLI commands into subdirectories matching command hierarchy:
dev/, go/, php/, build/, ci/, sdk/, pkg/, vm/, docs/, setup/, doctor/, test/, ai/
- Create shared/ package for common styles and utilities
- Add new `core ai` root command with claude subcommand
- Update package declarations and imports across all files
- Create commands.go entry points for each package
- Remove GUI-related files (moved to core-gui repo)
This makes the filesystem structure match the CLI command structure,
improving context capture and code organization.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:02:43 +00:00
|
|
|
sdkpkg "github.com/host-uk/core/pkg/sdk"
|
2026-01-30 00:47:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
2026-01-29 01:22:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
sdkHeaderStyle = lipgloss.NewStyle().
|
|
|
|
|
Bold(true).
|
|
|
|
|
Foreground(lipgloss.Color("#3b82f6"))
|
|
|
|
|
|
|
|
|
|
sdkSuccessStyle = lipgloss.NewStyle().
|
|
|
|
|
Bold(true).
|
|
|
|
|
Foreground(lipgloss.Color("#22c55e"))
|
|
|
|
|
|
|
|
|
|
sdkErrorStyle = lipgloss.NewStyle().
|
|
|
|
|
Bold(true).
|
|
|
|
|
Foreground(lipgloss.Color("#ef4444"))
|
|
|
|
|
|
|
|
|
|
sdkDimStyle = lipgloss.NewStyle().
|
|
|
|
|
Foreground(lipgloss.Color("#6b7280"))
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
var sdkCmd = &cobra.Command{
|
|
|
|
|
Use: "sdk",
|
|
|
|
|
Short: "SDK validation and API compatibility tools",
|
|
|
|
|
Long: `Tools for validating OpenAPI specs and checking API compatibility.
|
|
|
|
|
To generate SDKs, use: core build sdk
|
|
|
|
|
|
|
|
|
|
Commands:
|
|
|
|
|
diff Check for breaking API changes
|
|
|
|
|
validate Validate OpenAPI spec syntax`,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var diffBasePath string
|
|
|
|
|
var diffSpecPath string
|
|
|
|
|
|
|
|
|
|
var sdkDiffCmd = &cobra.Command{
|
|
|
|
|
Use: "diff",
|
|
|
|
|
Short: "Check for breaking API changes",
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
return runSDKDiff(diffBasePath, diffSpecPath)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var validateSpecPath string
|
|
|
|
|
|
|
|
|
|
var sdkValidateCmd = &cobra.Command{
|
|
|
|
|
Use: "validate",
|
|
|
|
|
Short: "Validate OpenAPI spec",
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
return runSDKValidate(validateSpecPath)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
// sdk diff flags
|
|
|
|
|
sdkDiffCmd.Flags().StringVar(&diffBasePath, "base", "", "Base spec (version tag or file)")
|
|
|
|
|
sdkDiffCmd.Flags().StringVar(&diffSpecPath, "spec", "", "Current spec file")
|
|
|
|
|
|
|
|
|
|
// sdk validate flags
|
|
|
|
|
sdkValidateCmd.Flags().StringVar(&validateSpecPath, "spec", "", "Path to OpenAPI spec file")
|
|
|
|
|
|
|
|
|
|
// Add subcommands
|
|
|
|
|
sdkCmd.AddCommand(sdkDiffCmd)
|
|
|
|
|
sdkCmd.AddCommand(sdkValidateCmd)
|
2026-01-29 01:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runSDKDiff(basePath, specPath string) error {
|
|
|
|
|
projectDir, err := os.Getwd()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to get working directory: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Detect current spec if not provided
|
|
|
|
|
if specPath == "" {
|
2026-01-29 18:13:51 +00:00
|
|
|
s := sdkpkg.New(projectDir, nil)
|
2026-01-29 01:22:40 +00:00
|
|
|
specPath, err = s.DetectSpec()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if basePath == "" {
|
|
|
|
|
return fmt.Errorf("--base is required (version tag or file path)")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("%s Checking for breaking changes\n", sdkHeaderStyle.Render("SDK Diff:"))
|
|
|
|
|
fmt.Printf(" Base: %s\n", sdkDimStyle.Render(basePath))
|
|
|
|
|
fmt.Printf(" Current: %s\n", sdkDimStyle.Render(specPath))
|
|
|
|
|
fmt.Println()
|
|
|
|
|
|
2026-01-29 18:13:51 +00:00
|
|
|
result, err := sdkpkg.Diff(basePath, specPath)
|
2026-01-29 01:22:40 +00:00
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("%s %v\n", sdkErrorStyle.Render("Error:"), err)
|
|
|
|
|
os.Exit(2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if result.Breaking {
|
|
|
|
|
fmt.Printf("%s %s\n", sdkErrorStyle.Render("Breaking:"), result.Summary)
|
|
|
|
|
for _, change := range result.Changes {
|
|
|
|
|
fmt.Printf(" - %s\n", change)
|
|
|
|
|
}
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("%s %s\n", sdkSuccessStyle.Render("OK:"), result.Summary)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runSDKValidate(specPath string) error {
|
|
|
|
|
projectDir, err := os.Getwd()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to get working directory: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 18:13:51 +00:00
|
|
|
s := sdkpkg.New(projectDir, &sdkpkg.Config{Spec: specPath})
|
2026-01-29 01:22:40 +00:00
|
|
|
|
|
|
|
|
fmt.Printf("%s Validating OpenAPI spec\n", sdkHeaderStyle.Render("SDK:"))
|
|
|
|
|
|
|
|
|
|
detectedPath, err := s.DetectSpec()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("%s %v\n", sdkErrorStyle.Render("Error:"), err)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf(" Spec: %s\n", sdkDimStyle.Render(detectedPath))
|
|
|
|
|
fmt.Printf("%s Spec is valid\n", sdkSuccessStyle.Render("OK:"))
|
|
|
|
|
return nil
|
|
|
|
|
}
|