diff --git a/internal/manager.go b/internal/manager.go index 4ce5bb4c..9173d318 100644 --- a/internal/manager.go +++ b/internal/manager.go @@ -20,13 +20,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/pterm/pterm" - "github.com/urfave/cli/v2" - "github.com/version-fox/vfox/internal/config" - "github.com/version-fox/vfox/internal/env" - "github.com/version-fox/vfox/internal/logger" - "github.com/version-fox/vfox/internal/toolset" - "github.com/version-fox/vfox/internal/util" "io" "net" "net/http" @@ -35,6 +28,14 @@ import ( "path/filepath" "strconv" "strings" + + "github.com/pterm/pterm" + "github.com/urfave/cli/v2" + "github.com/version-fox/vfox/internal/config" + "github.com/version-fox/vfox/internal/env" + "github.com/version-fox/vfox/internal/logger" + "github.com/version-fox/vfox/internal/toolset" + "github.com/version-fox/vfox/internal/util" ) const ( @@ -384,22 +385,24 @@ func (m *Manager) downloadPlugin(downloadUrl string) (string, error) { } func (m *Manager) Add(pluginName, url, alias string) error { + // For compatibility with older versions of plugin names / + if strings.Contains(pluginName, "/") { + pluginName = strings.Split(pluginName, "/")[1] + } pluginPath := url + pname := pluginName + if len(alias) > 0 { + pname = alias + } + installPath := filepath.Join(m.PathMeta.PluginPath, pname) + if util.FileExists(installPath) { + return fmt.Errorf("plugin named %s already exists", pname) + } + // official plugin if len(url) == 0 { - pname := pluginName - // For compatibility with older versions of plugin names / - if strings.Contains(pluginName, "/") { - pname = strings.Split(pluginName, "/")[1] - } - - installPath := filepath.Join(m.PathMeta.PluginPath, pname) - if util.FileExists(installPath) { - return fmt.Errorf("plugin %s already exists", pname) - } - - fmt.Printf("Fetching %s manifest... \n", pterm.Green(pname)) - pluginManifest, err := m.fetchPluginManifest(m.GetRegistryAddress(pname + ".json")) + fmt.Printf("Fetching %s manifest... \n", pterm.Green(pluginName)) + pluginManifest, err := m.fetchPluginManifest(m.GetRegistryAddress(pluginName + ".json")) if err != nil { return err } @@ -413,15 +416,6 @@ func (m *Manager) Add(pluginName, url, alias string) error { _ = os.RemoveAll(tempPlugin.Path) tempPlugin.Close() }() - // set alias name - pname := tempPlugin.Name - if len(alias) > 0 { - pname = alias - } - installPath := filepath.Join(m.PathMeta.PluginPath, pname) - if util.FileExists(installPath) { - return fmt.Errorf("plugin %s already exists", pname) - } if err = os.Rename(tempPlugin.Path, installPath); err != nil { return fmt.Errorf("install plugin error: %w", err) } diff --git a/internal/sdk.go b/internal/sdk.go index 8e078d2b..5329b34d 100644 --- a/internal/sdk.go +++ b/internal/sdk.go @@ -195,8 +195,7 @@ func (b *Sdk) preInstallSdk(info *Info, sdkDestPath string) (string, error) { func (b *Sdk) Uninstall(version Version) error { label := b.label(version) if !b.checkExists(version) { - pterm.Printf("%s is not installed...\n", pterm.Red(label)) - return fmt.Errorf("%s is not installed", label) + return fmt.Errorf("%s is not installed", pterm.Red(label)) } if b.Current() == version { b.clearEnvConfig(version) @@ -597,7 +596,7 @@ func (b *Sdk) Download(u *url.URL) (string, error) { } func (b *Sdk) label(version Version) string { - return fmt.Sprintf("%s@%s", strings.ToLower(b.Plugin.Name), version) + return fmt.Sprintf("%s@%s", strings.ToLower(b.Plugin.SdkName), version) } // NewSdk creates a new SDK instance.