cli/.core/plugin/skills/go.md
Snider a1306bc321 feat/ml-integration (#2)
Co-authored-by: Charon (snider-linux) <charon@lethean.io>
Co-authored-by: Snider <snider@host.uk.com>
Co-authored-by: Virgil <virgil@lethean.io>
Co-authored-by: Claude <developers@lethean.io>
Reviewed-on: #2
Co-authored-by: Snider <snider@lethean.io>
Co-committed-by: Snider <snider@lethean.io>
2026-02-16 06:19:09 +00:00

2.4 KiB

name description
core-go Use when creating Go packages or extending the core CLI.

Go Framework Patterns

Core CLI uses pkg/ for reusable packages. Use core go commands.

Package Structure

core/
├── main.go                 # CLI entry point
├── pkg/
│   ├── cli/               # CLI framework, output, errors
│   ├── {domain}/          # Domain package
│   │   ├── cmd_{name}.go  # Cobra command definitions
│   │   ├── service.go     # Business logic
│   │   └── *_test.go      # Tests
│   └── ...
└── internal/              # Private packages

Adding a CLI Command

  1. Create pkg/{domain}/cmd_{name}.go:
package domain

import (
    "forge.lthn.ai/core/cli/pkg/cli"
    "github.com/spf13/cobra"
)

func NewNameCmd() *cobra.Command {
    cmd := &cobra.Command{
        Use:   "name",
        Short: cli.T("domain.name.short"),
        RunE: func(cmd *cobra.Command, args []string) error {
            // Implementation
            cli.Success("Done")
            return nil
        },
    }
    return cmd
}
  1. Register in parent command.

CLI Output Helpers

import "forge.lthn.ai/core/cli/pkg/cli"

cli.Success("Operation completed")      // Green check
cli.Warning("Something to note")        // Yellow warning
cli.Error("Something failed")           // Red error
cli.Info("Informational message")       // Blue info
cli.Fatal(err)                          // Print error and exit 1

// Structured output
cli.Table(headers, rows)
cli.JSON(data)

i18n Pattern

// Use cli.T() for translatable strings
cli.T("domain.action.success")
cli.T("domain.action.error", "details", value)

// Define in pkg/i18n/locales/en.yaml:
domain:
  action:
    success: "Operation completed successfully"
    error: "Failed: {{.details}}"

Test Naming

func TestFeature_Good(t *testing.T) { /* happy path */ }
func TestFeature_Bad(t *testing.T)  { /* expected errors */ }
func TestFeature_Ugly(t *testing.T) { /* panics, edge cases */ }

Commands

Task Command
Run tests core go test
Coverage core go cov
Format core go fmt --fix
Lint core go lint
Build core build
Install core go install

Rules

  • CGO_ENABLED=0 for all builds
  • UK English in user-facing strings
  • All errors via cli.E("context", "message", err)
  • Table-driven tests preferred