pluginctl/info.go
Felipe Martin 71a7b0de11
Refactor codebase with improved structure and logging
- Restructured info.go with extracted helper functions for better readability
- Enhanced updateassets.go with cleaner asset processing logic and better error handling
- Improved client.go formatting and logging consistency
- Added logs.go for centralized logging functionality
- Updated dependencies in go.mod to include tint as direct dependency
- Cleaned up README.md with simplified installation instructions and structure
- Added comprehensive assets/ directory with build configuration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-14 17:14:12 +02:00

114 lines
3.1 KiB
Go

package pluginctl
import (
"fmt"
"path/filepath"
"github.com/mattermost/mattermost/server/public/model"
)
// InfoCommand implements the 'info' command functionality.
func InfoCommand() error {
manifest, err := LoadPluginManifest()
if err != nil {
return fmt.Errorf("failed to load plugin manifest: %w", err)
}
return PrintPluginInfo(manifest)
}
// PrintPluginInfo displays formatted plugin information.
func PrintPluginInfo(manifest *model.Manifest) error {
printBasicInfo(manifest)
printCodeComponents(manifest)
printSettingsSchema(manifest)
return nil
}
// printBasicInfo prints basic plugin information.
func printBasicInfo(manifest *model.Manifest) {
Logger.Info("Plugin Information:")
Logger.Info("==================")
Logger.Info("ID:", "value", manifest.Id)
Logger.Info("Name:", "value", manifest.Name)
Logger.Info("Version:", "value", manifest.Version)
minVersion := manifest.MinServerVersion
if minVersion == "" {
minVersion = "Not specified"
}
Logger.Info("Min MM Version:", "value", minVersion)
if manifest.Description != "" {
Logger.Info("Description:", "value", manifest.Description)
}
}
// printCodeComponents prints information about server and webapp code.
func printCodeComponents(manifest *model.Manifest) {
Logger.Info("Code Components:")
Logger.Info("================")
printServerCodeInfo(manifest)
printWebappCodeInfo(manifest)
}
// printServerCodeInfo prints server code information.
func printServerCodeInfo(manifest *model.Manifest) {
if HasServerCode(manifest) {
Logger.Info("Server Code:", "value", "Yes")
if manifest.Server != nil && len(manifest.Server.Executables) > 0 {
var executables []string
for platform := range manifest.Server.Executables {
executables = append(executables, platform)
}
Logger.Info("Executables:", "platforms", executables)
}
} else {
Logger.Info("Server Code:", "value", "No")
}
}
// printWebappCodeInfo prints webapp code information.
func printWebappCodeInfo(manifest *model.Manifest) {
if HasWebappCode(manifest) {
Logger.Info("Webapp Code:", "value", "Yes")
if manifest.Webapp != nil && manifest.Webapp.BundlePath != "" {
Logger.Info("Bundle Path:", "value", manifest.Webapp.BundlePath)
}
} else {
Logger.Info("Webapp Code:", "value", "No")
}
}
// printSettingsSchema prints settings schema information.
func printSettingsSchema(manifest *model.Manifest) {
value := "No"
if manifest.SettingsSchema != nil {
value = "Yes"
}
Logger.Info("Settings Schema:", "value", value)
}
// InfoCommandWithPath implements the 'info' command with a custom path.
func InfoCommandWithPath(path string) error {
manifest, err := LoadPluginManifestFromPath(path)
if err != nil {
return fmt.Errorf("failed to load plugin manifest from %s: %w", path, err)
}
return PrintPluginInfo(manifest)
}
// RunInfoCommand implements the 'info' command functionality with plugin path.
func RunInfoCommand(args []string, pluginPath string) error {
// Convert to absolute path
absPath, err := filepath.Abs(pluginPath)
if err != nil {
return fmt.Errorf("failed to resolve path: %w", err)
}
return InfoCommandWithPath(absPath)
}