From 0bc6d51b24afb863172cc2dec2be03935ce81a8b Mon Sep 17 00:00:00 2001 From: Felipe Martin Date: Mon, 28 Jul 2025 17:50:42 +0200 Subject: [PATCH] Refactor manifest command to use template-based field access MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- assets/build/_setup.mk | 8 ++++---- assets/build/versioning.mk | 2 +- cmd/pluginctl/main.go | 7 ++----- manifest.go | 39 +++++++++++++++++++------------------- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/assets/build/_setup.mk b/assets/build/_setup.mk index 4dbc745..9e694f8 100644 --- a/assets/build/_setup.mk +++ b/assets/build/_setup.mk @@ -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/.) diff --git a/assets/build/versioning.mk b/assets/build/versioning.mk index 1c63bba..ca7a31a 100644 --- a/assets/build/versioning.mk +++ b/assets/build/versioning.mk @@ -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)) diff --git a/cmd/pluginctl/main.go b/cmd/pluginctl/main.go index 96d5e59..ed79db3 100644 --- a/cmd/pluginctl/main.go +++ b/cmd/pluginctl/main.go @@ -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 diff --git a/manifest.go b/manifest.go index a5f959a..22f976a 100644 --- a/manifest.go +++ b/manifest.go @@ -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