added code to clone package manager

This commit is contained in:
2021-10-01 14:38:13 +04:00
parent be985942b9
commit fc5e834552
10 changed files with 250 additions and 9 deletions

43
plugin/packageManager.go Normal file
View File

@@ -0,0 +1,43 @@
package plugin
import (
"git.sr.ht/~akilan1999/p2p-rendering-computation/config"
"github.com/go-git/go-git/v5"
"os"
"net/url"
"strings"
)
// DownloadPlugin This functions downloads package from
// a git repo
func DownloadPlugin(pluginurl string) error {
// paring plugin url
u, err := url.Parse(pluginurl)
if err != nil {
return err
}
path := u.Path
// Trim first character of the string
path = path[1:]
// trim last element of the string
path = path[:len(path)-1]
// Replaces / with _
folder := strings.Replace(path, "/", "_", -1)
// Reads plugin path from the config path
config, err := config.ConfigInit()
if err != nil {
return err
}
// clones a repo and stores it at the plugin directory
_, err = git.PlainClone(config.PluginPath + "/" + folder, false, &git.CloneOptions{
URL: pluginurl,
Progress: os.Stdout,
})
// returns error if raised
if err != nil {
return err
}
return nil
}