- Add logger.go with public Logger variable and InitLogger function - Replace all fmt.Printf/fmt.Fprintf calls with structured Logger.Info/Logger.Error - Initialize logger in main function for consistent access across packages - Keep fmt.Errorf for proper error creation (standard Go practice) - Add tint dependency for colorized terminal output with timestamps - Convert user output to structured logging with key-value pairs - Update info command to use structured logging for plugin details - Update updateassets command to use structured progress logging - Update version command to use structured logging - Update authentication logging in client.go with structured fields - Update enable/disable commands to use structured logging - Remove unused fmt imports after conversion All output now uses slog with tint for beautiful, structured, colorized logging while maintaining proper error handling with fmt.Errorf for error creation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
98 lines
2.6 KiB
Go
98 lines
2.6 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 {
|
|
Logger.Info("Plugin Information:")
|
|
Logger.Info("==================")
|
|
|
|
// Basic plugin info
|
|
Logger.Info("ID:", "value", manifest.Id)
|
|
Logger.Info("Name:", "value", manifest.Name)
|
|
Logger.Info("Version:", "value", manifest.Version)
|
|
|
|
// Minimum Mattermost version
|
|
if manifest.MinServerVersion != "" {
|
|
Logger.Info("Min MM Version:", "value", manifest.MinServerVersion)
|
|
} else {
|
|
Logger.Info("Min MM Version:", "value", "Not specified")
|
|
}
|
|
|
|
// Description if available
|
|
if manifest.Description != "" {
|
|
Logger.Info("Description:", "value", manifest.Description)
|
|
}
|
|
|
|
Logger.Info("Code Components:")
|
|
Logger.Info("================")
|
|
|
|
// Server code presence
|
|
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")
|
|
}
|
|
|
|
// Webapp code presence
|
|
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")
|
|
}
|
|
|
|
// Settings schema
|
|
if manifest.SettingsSchema != nil {
|
|
Logger.Info("Settings Schema:", "value", "Yes")
|
|
} else {
|
|
Logger.Info("Settings Schema:", "value", "No")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// 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)
|
|
}
|