Refactor version tracking to separate validation and update logic
- Split ValidateAndUpdateVersion into validation-only function - Add dedicated UpdatePluginCtlVersion function for version updates - Update updateassets command to use new version update function - Improve separation of concerns and code maintainability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
353cc9efc7
commit
3b412a0a6b
2 changed files with 32 additions and 9 deletions
26
pluginctl.go
26
pluginctl.go
|
@ -108,7 +108,7 @@ func SavePluginCtlConfig(manifest *model.Manifest, config *PluginCtlConfig) {
|
|||
manifest.Props["pluginctl"] = config
|
||||
}
|
||||
|
||||
// ValidateAndUpdateVersion checks the plugin version and updates it if necessary.
|
||||
// ValidateAndUpdateVersion checks the plugin version for compatibility.
|
||||
func ValidateAndUpdateVersion(pluginPath string) error {
|
||||
// Load the manifest
|
||||
manifest, err := LoadPluginManifestFromPath(pluginPath)
|
||||
|
@ -135,8 +135,27 @@ func ValidateAndUpdateVersion(pluginPath string) error {
|
|||
config.Version, currentVersion)
|
||||
}
|
||||
|
||||
// Update version if different
|
||||
if config.Version != currentVersion {
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdatePluginCtlVersion updates the pluginctl version in the manifest.
|
||||
func UpdatePluginCtlVersion(pluginPath string) error {
|
||||
// Load the manifest
|
||||
manifest, err := LoadPluginManifestFromPath(pluginPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load plugin manifest: %w", err)
|
||||
}
|
||||
|
||||
// Get current pluginctl version
|
||||
currentVersion := GetVersion()
|
||||
|
||||
// Parse existing pluginctl config
|
||||
config, err := ParsePluginCtlConfig(manifest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse pluginctl config: %w", err)
|
||||
}
|
||||
|
||||
// Update version
|
||||
config.Version = currentVersion
|
||||
SavePluginCtlConfig(manifest, config)
|
||||
|
||||
|
@ -144,7 +163,6 @@ func ValidateAndUpdateVersion(pluginPath string) error {
|
|||
if err := WritePluginManifest(manifest, pluginPath); err != nil {
|
||||
return fmt.Errorf("failed to update version in manifest: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -87,6 +87,11 @@ Examples:
|
|||
|
||||
Logger.Info("Assets updated successfully!", "files_updated", updatedCount)
|
||||
|
||||
// Store the current pluginctl version in the manifest after successful update
|
||||
if err := UpdatePluginCtlVersion(pluginPath); err != nil {
|
||||
return fmt.Errorf("failed to save version to manifest: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue