From 9f304d26c19fa202b4cb9009111163d2edb2260e Mon Sep 17 00:00:00 2001 From: Akilan Selvacoumar Date: Sat, 9 Oct 2021 18:03:04 +0400 Subject: [PATCH] Implemented a package manager to remove plugins --- cmd/action.go | 9 +++++++++ cmd/flags.go | 10 +++++++++- plugin/packageManager.go | 22 +++++++++++++++++++++- plugin/plugin.go | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/cmd/action.go b/cmd/action.go index 6fb03f8..21eec91 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -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 diff --git a/cmd/flags.go b/cmd/flags.go index 9315a8e..d9feac6 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -32,8 +32,9 @@ var ( // -- REMOVE ON REGULAR RELEASE -- Generate string Modulename string - PullPlugin string //-------------------------------- + PullPlugin string + RemovePlugin string ) var AppConfigFlags = []cli.Flag{ @@ -217,4 +218,11 @@ var AppConfigFlags = []cli.Flag{ EnvVars: []string{"PULLPLUGIN"}, Destination: &PullPlugin, }, + &cli.StringFlag{ + Name: "RemovePlugin", + Aliases: []string{"rp"}, + Usage: "Removes plugin", + EnvVars: []string{"REMOVEPLUGIN"}, + Destination: &RemovePlugin, + }, } \ No newline at end of file diff --git a/plugin/packageManager.go b/plugin/packageManager.go index 825874f..5b7bf15 100644 --- a/plugin/packageManager.go +++ b/plugin/packageManager.go @@ -3,8 +3,8 @@ package plugin import ( "git.sr.ht/~akilan1999/p2p-rendering-computation/config" "github.com/go-git/go-git/v5" - "os" "net/url" + "os" "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 } \ No newline at end of file diff --git a/plugin/plugin.go b/plugin/plugin.go index 06145e4..0e8961c 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -93,6 +93,24 @@ func DetectPlugins()(*Plugins,error){ 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 func RunPlugin(pluginName string ,IPAddresses []*ExecuteIP) (*Plugin,error) { plugins, err := DetectPlugins()