Implemented a package manager to remove plugins
This commit is contained in:
@@ -279,6 +279,15 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if RemovePlugin != "" {
|
||||||
|
err := plugin.DeletePlugin(RemovePlugin)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
} else {
|
||||||
|
fmt.Println("Success")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
10
cmd/flags.go
10
cmd/flags.go
@@ -32,8 +32,9 @@ var (
|
|||||||
// -- REMOVE ON REGULAR RELEASE --
|
// -- REMOVE ON REGULAR RELEASE --
|
||||||
Generate string
|
Generate string
|
||||||
Modulename string
|
Modulename string
|
||||||
PullPlugin string
|
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
PullPlugin string
|
||||||
|
RemovePlugin string
|
||||||
)
|
)
|
||||||
|
|
||||||
var AppConfigFlags = []cli.Flag{
|
var AppConfigFlags = []cli.Flag{
|
||||||
@@ -217,4 +218,11 @@ var AppConfigFlags = []cli.Flag{
|
|||||||
EnvVars: []string{"PULLPLUGIN"},
|
EnvVars: []string{"PULLPLUGIN"},
|
||||||
Destination: &PullPlugin,
|
Destination: &PullPlugin,
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "RemovePlugin",
|
||||||
|
Aliases: []string{"rp"},
|
||||||
|
Usage: "Removes plugin",
|
||||||
|
EnvVars: []string{"REMOVEPLUGIN"},
|
||||||
|
Destination: &RemovePlugin,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,8 @@ package plugin
|
|||||||
import (
|
import (
|
||||||
"git.sr.ht/~akilan1999/p2p-rendering-computation/config"
|
"git.sr.ht/~akilan1999/p2p-rendering-computation/config"
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"os"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,5 +39,25 @@ func DownloadPlugin(pluginurl string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func DeletePlugin(pluginname string) error {
|
||||||
|
config, err := config.ConfigInit()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin, err := SearchPlugin(pluginname)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the directory holding the plugin
|
||||||
|
err = os.RemoveAll(config.PluginPath + "/" + plugin.FolderName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -93,6 +93,24 @@ func DetectPlugins()(*Plugins,error){
|
|||||||
return plugins,nil
|
return plugins,nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SearchPlugin Detects plugin information based on the
|
||||||
|
// name provided on the parameter
|
||||||
|
func SearchPlugin(pluginname string) (*Plugin,error) {
|
||||||
|
plugins, err := DetectPlugins()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop ot find the plugin name that matches
|
||||||
|
for _, plugin := range plugins.PluginsDetected {
|
||||||
|
if pluginname == plugin.FolderName {
|
||||||
|
return plugin, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("plugin not detected")
|
||||||
|
}
|
||||||
|
|
||||||
// RunPlugin Executes plugins based on the plugin name provided
|
// RunPlugin Executes plugins based on the plugin name provided
|
||||||
func RunPlugin(pluginName string ,IPAddresses []*ExecuteIP) (*Plugin,error) {
|
func RunPlugin(pluginName string ,IPAddresses []*ExecuteIP) (*Plugin,error) {
|
||||||
plugins, err := DetectPlugins()
|
plugins, err := DetectPlugins()
|
||||||
|
|||||||
Reference in New Issue
Block a user