mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Start plugin support and plugin manager
This commit is contained in:
46
cmd/micro/manager/fetch.go
Normal file
46
cmd/micro/manager/fetch.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package manager
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/zyedidia/micro/cmd/micro/config"
|
||||
git "gopkg.in/src-d/go-git.v4"
|
||||
)
|
||||
|
||||
// NewPluginInfoFromUrl creates a new PluginInfo from a URL by fetching
|
||||
// the data at that URL and parsing the JSON (running a GET request at
|
||||
// the URL should return the JSON for a plugin info)
|
||||
func NewPluginInfoFromUrl(url string) (*PluginInfo, error) {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
dat, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewPluginInfo(dat)
|
||||
}
|
||||
|
||||
// FetchRepo downloads this plugin's git repository
|
||||
func (i *PluginInfo) FetchRepo() error {
|
||||
_, err := git.PlainClone(path.Join(config.ConfigDir, "plugin", i.Name), false, &git.CloneOptions{
|
||||
URL: i.Repo,
|
||||
Progress: nil,
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *PluginInfo) FetchDeps() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *PluginInfo) PostInstallHooks() error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user