feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
// Package sdkcmd provides SDK validation and API compatibility commands.
|
|
|
|
|
//
|
|
|
|
|
// Commands:
|
|
|
|
|
// - sdk diff: check for breaking API changes between spec versions
|
|
|
|
|
// - sdk validate: validate OpenAPI spec syntax
|
|
|
|
|
//
|
|
|
|
|
// For SDK generation, use: core build sdk
|
|
|
|
|
package sdkcmd
|
|
|
|
|
|
|
|
|
|
import (
|
2026-04-01 13:17:59 +00:00
|
|
|
"context"
|
2026-03-26 17:41:53 +00:00
|
|
|
"dappco.re/go/core/build/internal/ax"
|
2026-03-22 01:53:16 +00:00
|
|
|
"dappco.re/go/core/build/pkg/sdk"
|
|
|
|
|
"dappco.re/go/core/i18n"
|
|
|
|
|
coreerr "dappco.re/go/core/log"
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
"forge.lthn.ai/core/cli/pkg/cli"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
cli.RegisterCommands(AddSDKCommands)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SDK styles (aliases to shared)
|
|
|
|
|
var (
|
|
|
|
|
sdkHeaderStyle = cli.TitleStyle
|
|
|
|
|
sdkSuccessStyle = cli.SuccessStyle
|
|
|
|
|
sdkErrorStyle = cli.ErrorStyle
|
|
|
|
|
sdkDimStyle = cli.DimStyle
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var sdkCmd = &cli.Command{
|
2026-03-17 02:31:47 +00:00
|
|
|
Use: "sdk",
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var diffBasePath string
|
|
|
|
|
var diffSpecPath string
|
|
|
|
|
|
|
|
|
|
var sdkDiffCmd = &cli.Command{
|
2026-03-17 02:31:47 +00:00
|
|
|
Use: "diff",
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
RunE: func(cmd *cli.Command, args []string) error {
|
|
|
|
|
return runSDKDiff(diffBasePath, diffSpecPath)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var validateSpecPath string
|
|
|
|
|
|
|
|
|
|
var sdkValidateCmd = &cli.Command{
|
2026-03-17 02:31:47 +00:00
|
|
|
Use: "validate",
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
RunE: func(cmd *cli.Command, args []string) error {
|
|
|
|
|
return runSDKValidate(validateSpecPath)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 02:31:47 +00:00
|
|
|
func setSDKI18n() {
|
|
|
|
|
sdkCmd.Short = i18n.T("cmd.sdk.short")
|
|
|
|
|
sdkCmd.Long = i18n.T("cmd.sdk.long")
|
|
|
|
|
sdkDiffCmd.Short = i18n.T("cmd.sdk.diff.short")
|
|
|
|
|
sdkDiffCmd.Long = i18n.T("cmd.sdk.diff.long")
|
|
|
|
|
sdkValidateCmd.Short = i18n.T("cmd.sdk.validate.short")
|
|
|
|
|
sdkValidateCmd.Long = i18n.T("cmd.sdk.validate.long")
|
|
|
|
|
}
|
|
|
|
|
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
// AddSDKCommands registers the 'sdk' command and all subcommands.
|
2026-03-31 18:33:36 +01:00
|
|
|
//
|
|
|
|
|
// sdkcmd.AddSDKCommands(root)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
func AddSDKCommands(root *cli.Command) {
|
2026-03-17 02:31:47 +00:00
|
|
|
setSDKI18n()
|
|
|
|
|
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
// sdk diff flags
|
|
|
|
|
sdkDiffCmd.Flags().StringVar(&diffBasePath, "base", "", i18n.T("cmd.sdk.diff.flag.base"))
|
|
|
|
|
sdkDiffCmd.Flags().StringVar(&diffSpecPath, "spec", "", i18n.T("cmd.sdk.diff.flag.spec"))
|
|
|
|
|
|
|
|
|
|
// sdk validate flags
|
|
|
|
|
sdkValidateCmd.Flags().StringVar(&validateSpecPath, "spec", "", i18n.T("common.flag.spec"))
|
|
|
|
|
|
|
|
|
|
// Add subcommands
|
|
|
|
|
sdkCmd.AddCommand(sdkDiffCmd)
|
|
|
|
|
sdkCmd.AddCommand(sdkValidateCmd)
|
|
|
|
|
|
|
|
|
|
root.AddCommand(sdkCmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runSDKDiff(basePath, specPath string) error {
|
2026-03-26 17:41:53 +00:00
|
|
|
projectDir, err := ax.Getwd()
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
if err != nil {
|
2026-03-16 21:03:21 +00:00
|
|
|
return coreerr.E("sdk.Diff", "failed to get working directory", err)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if specPath == "" {
|
|
|
|
|
s := sdk.New(projectDir, nil)
|
|
|
|
|
specPath, err = s.DetectSpec()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if basePath == "" {
|
2026-03-16 21:03:21 +00:00
|
|
|
return coreerr.E("sdk.Diff", i18n.T("cmd.sdk.diff.error.base_required"), nil)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-17 07:54:19 +00:00
|
|
|
cli.Print("%s %s\n", sdkHeaderStyle.Render(i18n.T("cmd.sdk.diff.label")), i18n.ProgressSubject("check", "breaking changes"))
|
|
|
|
|
cli.Print(" %s %s\n", i18n.T("cmd.sdk.diff.base_label"), sdkDimStyle.Render(basePath))
|
|
|
|
|
cli.Print(" %s %s\n", i18n.Label("current"), sdkDimStyle.Render(specPath))
|
|
|
|
|
cli.Blank()
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
|
|
|
|
|
result, err := sdk.Diff(basePath, specPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return cli.Exit(2, cli.Wrap(err, i18n.Label("error")))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if result.Breaking {
|
2026-03-17 07:54:19 +00:00
|
|
|
cli.Print("%s %s\n", sdkErrorStyle.Render(i18n.T("cmd.sdk.diff.breaking")), result.Summary)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
for _, change := range result.Changes {
|
2026-03-17 07:54:19 +00:00
|
|
|
cli.Print(" - %s\n", change)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|
|
|
|
|
return cli.Exit(1, cli.Err("%s", result.Summary))
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 07:54:19 +00:00
|
|
|
cli.Print("%s %s\n", sdkSuccessStyle.Render(i18n.T("cmd.sdk.label.ok")), result.Summary)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runSDKValidate(specPath string) error {
|
2026-03-26 17:41:53 +00:00
|
|
|
projectDir, err := ax.Getwd()
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
if err != nil {
|
2026-03-16 21:03:21 +00:00
|
|
|
return coreerr.E("sdk.Validate", "failed to get working directory", err)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-01 13:17:59 +00:00
|
|
|
return runSDKValidateInDir(context.Background(), projectDir, specPath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runSDKValidateInDir(ctx context.Context, projectDir, specPath string) error {
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
s := sdk.New(projectDir, &sdk.Config{Spec: specPath})
|
|
|
|
|
|
2026-03-17 07:54:19 +00:00
|
|
|
cli.Print("%s %s\n", sdkHeaderStyle.Render(i18n.T("cmd.sdk.label.sdk")), i18n.T("cmd.sdk.validate.validating"))
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
|
2026-04-01 13:17:59 +00:00
|
|
|
detectedPath, err := s.ValidateSpec(ctx)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
if err != nil {
|
2026-03-17 07:54:19 +00:00
|
|
|
cli.Print("%s %v\n", sdkErrorStyle.Render(i18n.Label("error")), err)
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 07:54:19 +00:00
|
|
|
cli.Print(" %s %s\n", i18n.Label("spec"), sdkDimStyle.Render(detectedPath))
|
|
|
|
|
cli.Print("%s %s\n", sdkSuccessStyle.Render(i18n.T("cmd.sdk.label.ok")), i18n.T("cmd.sdk.validate.valid"))
|
feat: extract build/, release/, sdk/ from go-devops
Build system (8 builders, signing, archiving), release pipeline
(7 publishers, versioning, changelog), and SDK generation
(OpenAPI diff, code gen). 18K LOC, all tests pass except Go
builder workspace isolation (pre-existing).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-09 12:37:36 +00:00
|
|
|
return nil
|
|
|
|
|
}
|