Skip to content

Commit

Permalink
fix: keep the plugin name consistent (#219)
Browse files Browse the repository at this point in the history
This change, weakens the name of the plugin itself. It's based on the indexed repository and the alias name entered by the user. 

* Fix about adding plugin with alias

* Fix the prompt when plugin alias is used

* fix: duplicate error message

fix #218 
fix #220 
---------

Co-authored-by: lihan <lihan@apache.org>
  • Loading branch information
yanecc and aooohan authored Apr 21, 2024
1 parent 4cf47df commit 7f0070c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
52 changes: 23 additions & 29 deletions internal/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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 <category>/<plugin-name>
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 <category>/<plugin-name>
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
}
Expand All @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7f0070c

Please sign in to comment.