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:
parent
18bfca1c2c
commit
0bc6d51b24
4 changed files with 27 additions and 29 deletions
|
@ -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)
|
BUILD_TAG_CURRENT = $(shell git tag --points-at HEAD)
|
||||||
|
|
||||||
# Extract the plugin id from the manifest.
|
# Extract the plugin id from the manifest.
|
||||||
PLUGIN_ID ?= $(shell pluginctl manifest id)
|
PLUGIN_ID ?= $(shell pluginctl manifest get '{{.id}}')
|
||||||
ifeq ($(PLUGIN_ID),)
|
ifeq ($(PLUGIN_ID),)
|
||||||
$(error "Cannot parse id from $(MANIFEST_FILE)")
|
$(error "Cannot parse id from $(MANIFEST_FILE)")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Extract the plugin version from the manifest.
|
# Extract the plugin version from the manifest.
|
||||||
PLUGIN_VERSION ?= $(shell pluginctl manifest version)
|
PLUGIN_VERSION ?= $(shell pluginctl manifest get '{{.version}}')
|
||||||
ifeq ($(PLUGIN_VERSION),)
|
ifeq ($(PLUGIN_VERSION),)
|
||||||
$(error "Cannot parse version from $(MANIFEST_FILE)")
|
$(error "Cannot parse version from $(MANIFEST_FILE)")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Determine if a server is defined in the manifest.
|
# 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.
|
# 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
|
# Determine if a /public folder is in use
|
||||||
HAS_PUBLIC ?= $(wildcard public/.)
|
HAS_PUBLIC ?= $(wildcard public/.)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
# Used for semver bumping
|
# Used for semver bumping
|
||||||
PROTECTED_BRANCH := master
|
PROTECTED_BRANCH := master
|
||||||
APP_NAME := $(shell pluginctl manifest id)
|
APP_NAME := $(shell pluginctl manifest get '{{.id}}')
|
||||||
CURRENT_VERSION := $(shell git describe --abbrev=0 --tags)
|
CURRENT_VERSION := $(shell git describe --abbrev=0 --tags)
|
||||||
VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(CURRENT_VERSION))))
|
VERSION_PARTS := $(subst ., ,$(subst v,,$(subst -rc, ,$(CURRENT_VERSION))))
|
||||||
MAJOR := $(word 1,$(VERSION_PARTS))
|
MAJOR := $(word 1,$(VERSION_PARTS))
|
||||||
|
|
|
@ -131,7 +131,7 @@ Commands:
|
||||||
reset Reset plugin from current directory (disable then enable)
|
reset Reset plugin from current directory (disable then enable)
|
||||||
deploy Upload and enable plugin bundle to Mattermost server
|
deploy Upload and enable plugin bundle to Mattermost server
|
||||||
updateassets Update plugin files from embedded assets
|
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)
|
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)
|
create-plugin Create a new plugin from the starter template (supports --name and --module flags)
|
||||||
help Show this help message
|
help Show this help message
|
||||||
|
@ -146,10 +146,7 @@ Examples:
|
||||||
pluginctl deploy # Upload and enable plugin bundle from ./dist/
|
pluginctl deploy # Upload and enable plugin bundle from ./dist/
|
||||||
pluginctl deploy --bundle-path ./bundle.tar.gz # Deploy specific bundle file
|
pluginctl deploy --bundle-path ./bundle.tar.gz # Deploy specific bundle file
|
||||||
pluginctl updateassets # Update plugin files from embedded assets
|
pluginctl updateassets # Update plugin files from embedded assets
|
||||||
pluginctl manifest id # Get plugin ID
|
pluginctl manifest get '{{.id}}' # Get any manifest field using templates
|
||||||
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 check # Validate plugin manifest
|
pluginctl manifest check # Validate plugin manifest
|
||||||
pluginctl logs # View recent plugin logs
|
pluginctl logs # View recent plugin logs
|
||||||
pluginctl logs --watch # Watch plugin logs in real-time
|
pluginctl logs --watch # Watch plugin logs in real-time
|
||||||
|
|
39
manifest.go
39
manifest.go
|
@ -1,14 +1,16 @@
|
||||||
package pluginctl
|
package pluginctl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RunManifestCommand implements the 'manifest' command functionality with subcommands.
|
// RunManifestCommand implements the 'manifest' command functionality with subcommands.
|
||||||
func RunManifestCommand(args []string, pluginPath string) error {
|
func RunManifestCommand(args []string, pluginPath string) error {
|
||||||
if len(args) == 0 {
|
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
|
// Convert to absolute path
|
||||||
|
@ -25,24 +27,24 @@ func RunManifestCommand(args []string, pluginPath string) error {
|
||||||
|
|
||||||
subcommand := args[0]
|
subcommand := args[0]
|
||||||
switch subcommand {
|
switch subcommand {
|
||||||
case "id":
|
case "get":
|
||||||
fmt.Println(manifest.Id)
|
if len(args) < 2 {
|
||||||
case "name":
|
return fmt.Errorf("get subcommand requires a template expression (e.g., {{.id}}, {{.version}})")
|
||||||
fmt.Println(manifest.Name)
|
|
||||||
case "version":
|
|
||||||
fmt.Println(manifest.Version)
|
|
||||||
case "has_server":
|
|
||||||
if HasServerCode(manifest) {
|
|
||||||
fmt.Println("true")
|
|
||||||
} else {
|
|
||||||
fmt.Println("false")
|
|
||||||
}
|
}
|
||||||
case "has_webapp":
|
templateStr := args[1]
|
||||||
if HasWebappCode(manifest) {
|
|
||||||
fmt.Println("true")
|
// Parse and execute template with manifest as context
|
||||||
} else {
|
tmpl, err := template.New("manifest").Parse(templateStr)
|
||||||
fmt.Println("false")
|
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":
|
case "check":
|
||||||
if err := manifest.IsValid(); err != nil {
|
if err := manifest.IsValid(); err != nil {
|
||||||
Logger.Error("Plugin manifest validation failed", "error", err)
|
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")
|
Logger.Info("Plugin manifest is valid")
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown subcommand: %s. Available subcommands: id, version, has_server, has_webapp, check",
|
return fmt.Errorf("unknown subcommand: %s. Available subcommands: get {{.field_name}}, check", subcommand)
|
||||||
subcommand)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue