Refactor manifest command to use template-based field access

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>
This commit is contained in:
Felipe M 2025-07-28 17:50:42 +02:00
parent 18bfca1c2c
commit 0bc6d51b24
No known key found for this signature in database
GPG key ID: 52E5D65FCF99808A
4 changed files with 27 additions and 29 deletions

View file

@ -10,22 +10,22 @@ BUILD_TAG_LATEST = $(shell git describe --tags --match 'v*' --abbrev=0 2>/dev/nu
BUILD_TAG_CURRENT = $(shell git tag --points-at HEAD)
# Extract the plugin id from the manifest.
PLUGIN_ID ?= $(shell pluginctl manifest id)
PLUGIN_ID ?= $(shell pluginctl manifest get '{{.id}}')
ifeq ($(PLUGIN_ID),)
$(error "Cannot parse id from $(MANIFEST_FILE)")
endif
# Extract the plugin version from the manifest.
PLUGIN_VERSION ?= $(shell pluginctl manifest version)
PLUGIN_VERSION ?= $(shell pluginctl manifest get '{{.version}}')
ifeq ($(PLUGIN_VERSION),)
$(error "Cannot parse version from $(MANIFEST_FILE)")
endif
# Determine if a server is defined in the manifest.
HAS_SERVER ?= $(shell pluginctl manifest has_server)
HAS_SERVER ?= $(shell pluginctl manifest get '{{.has_server}}')
# Determine if a webapp is defined in the manifest.
HAS_WEBAPP ?= $(shell pluginctl manifest has_webapp)
HAS_WEBAPP ?= $(shell pluginctl manifest get '{{.has_webapp}}')
# Determine if a /public folder is in use
HAS_PUBLIC ?= $(wildcard public/.)

View file

@ -4,7 +4,7 @@
# Used for semver bumping
PROTECTED_BRANCH := master
APP_NAME := $(shell pluginctl manifest id)
APP_NAME := $(shell pluginctl manifest get '{{.id}}')
CURRENT_VERSION := $(shell git describe --abbrev=0 --tags)
VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(CURRENT_VERSION))))
MAJOR := $(word 1,$(VERSION_PARTS))

View file

@ -131,7 +131,7 @@ Commands:
reset Reset plugin from current directory (disable then enable)
deploy Upload and enable plugin bundle to Mattermost server
updateassets Update plugin files from embedded assets
manifest Get plugin manifest information (id, version, has_server, has_webapp, check)
manifest Get plugin manifest information using templates (get {{.field}}, check)
logs View plugin logs (use --watch to follow logs in real-time)
create-plugin Create a new plugin from the starter template (supports --name and --module flags)
help Show this help message
@ -146,10 +146,7 @@ Examples:
pluginctl deploy # Upload and enable plugin bundle from ./dist/
pluginctl deploy --bundle-path ./bundle.tar.gz # Deploy specific bundle file
pluginctl updateassets # Update plugin files from embedded assets
pluginctl manifest id # Get plugin ID
pluginctl manifest version # Get plugin version
pluginctl manifest has_server # Check if plugin has server code
pluginctl manifest has_webapp # Check if plugin has webapp code
pluginctl manifest get '{{.id}}' # Get any manifest field using templates
pluginctl manifest check # Validate plugin manifest
pluginctl logs # View recent plugin logs
pluginctl logs --watch # Watch plugin logs in real-time

View file

@ -1,14 +1,16 @@
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: id, version, has_server, has_webapp, check")
return fmt.Errorf("manifest command requires a subcommand: get {{.field_name}}, check")
}
// Convert to absolute path
@ -25,24 +27,24 @@ func RunManifestCommand(args []string, pluginPath string) error {
subcommand := args[0]
switch subcommand {
case "id":
fmt.Println(manifest.Id)
case "name":
fmt.Println(manifest.Name)
case "version":
fmt.Println(manifest.Version)
case "has_server":
if HasServerCode(manifest) {
fmt.Println("true")
} else {
fmt.Println("false")
case "get":
if len(args) < 2 {
return fmt.Errorf("get subcommand requires a template expression (e.g., {{.id}}, {{.version}})")
}
case "has_webapp":
if HasWebappCode(manifest) {
fmt.Println("true")
} else {
fmt.Println("false")
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)
@ -51,8 +53,7 @@ func RunManifestCommand(args []string, pluginPath string) error {
}
Logger.Info("Plugin manifest is valid")
default:
return fmt.Errorf("unknown subcommand: %s. Available subcommands: id, version, has_server, has_webapp, check",
subcommand)
return fmt.Errorf("unknown subcommand: %s. Available subcommands: get {{.field_name}}, check", subcommand)
}
return nil