Replace individual subcommands (id, version, has_server, has_webapp) with a unified 'get {{.field_name}}' pattern that uses Go templates to access any field from the manifest JSON dynamically. - Update manifest.go to parse and execute Go templates against manifest data - Update makefile calls in _setup.mk and versioning.mk to use new syntax - Update help documentation to reflect template-based usage - Provides more flexibility for accessing any manifest field without code changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package pluginctl
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"path/filepath"
|
|
"text/template"
|
|
)
|
|
|
|
// RunManifestCommand implements the 'manifest' command functionality with subcommands.
|
|
func RunManifestCommand(args []string, pluginPath string) error {
|
|
if len(args) == 0 {
|
|
return fmt.Errorf("manifest command requires a subcommand: get {{.field_name}}, check")
|
|
}
|
|
|
|
// Convert to absolute path
|
|
absPath, err := filepath.Abs(pluginPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to resolve path: %w", err)
|
|
}
|
|
|
|
// Load plugin manifest
|
|
manifest, err := LoadPluginManifestFromPath(absPath)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to load plugin manifest: %w", err)
|
|
}
|
|
|
|
subcommand := args[0]
|
|
switch subcommand {
|
|
case "get":
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("get subcommand requires a template expression (e.g., {{.id}}, {{.version}})")
|
|
}
|
|
templateStr := args[1]
|
|
|
|
// Parse and execute template with manifest as context
|
|
tmpl, err := template.New("manifest").Parse(templateStr)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to parse template: %w", err)
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
if err := tmpl.Execute(&buf, manifest); err != nil {
|
|
return fmt.Errorf("failed to execute template: %w", err)
|
|
}
|
|
|
|
fmt.Print(buf.String())
|
|
case "check":
|
|
if err := manifest.IsValid(); err != nil {
|
|
Logger.Error("Plugin manifest validation failed", "error", err)
|
|
|
|
return err
|
|
}
|
|
Logger.Info("Plugin manifest is valid")
|
|
default:
|
|
return fmt.Errorf("unknown subcommand: %s. Available subcommands: get {{.field_name}}, check", subcommand)
|
|
}
|
|
|
|
return nil
|
|
}
|