pms support
This commit is contained in:
+22
-19
@@ -1,46 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Package struct {
|
||||
type RepoResponse struct {
|
||||
Message string `json:"message"`
|
||||
Name string `json:"name"`
|
||||
Repo string `json:"repo"`
|
||||
}
|
||||
|
||||
type PackageVersion struct {
|
||||
Author string `json:"author"`
|
||||
Description string `json:"description"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type PackageIndex struct {
|
||||
Name string `json:"name"`
|
||||
Repo string `json:"repo"`
|
||||
}
|
||||
|
||||
func installPackage(packageName, packageVersion string) {
|
||||
var pkgidx PackageIndex
|
||||
jsonBody := []byte(fmt.Sprintf(`{"name": "%s"}`, packageName))
|
||||
resBody := sendRequest(http.MethodGet, "http://localhost:3000", jsonBody)
|
||||
err := json.Unmarshal(resBody.Body, &pkgidx)
|
||||
fmt.Printf("Fetching %s\n", packageName)
|
||||
repoURL, err := getRepoURL(packageName)
|
||||
if err != nil {
|
||||
fmt.Println("Json Error: ", err)
|
||||
fmt.Printf("Error getting repo URL: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("repo: %s\n", pkgidx.Repo)
|
||||
|
||||
repoU, err := url.Parse(pkgidx.Repo)
|
||||
repoU, err := url.Parse(repoURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
fmt.Printf("Error parsing repo URL: %s\n", err)
|
||||
}
|
||||
|
||||
if packageVersion == "" {
|
||||
packageVersion = getLatestVersion(repoU.Path)
|
||||
fmt.Printf("Found version %s\n", packageVersion)
|
||||
}
|
||||
fmt.Printf("Downloading %s %s\n", packageName, packageVersion)
|
||||
downloadPackage(repoU.Path, packageVersion)
|
||||
if err := os.Mkdir("wyst_tmp", os.ModePerm); err != nil {
|
||||
ERR := fmt.Sprintf("%s", err)
|
||||
if !strings.Contains(strings.ToLower(ERR), "file exists") {
|
||||
panic(ERR)
|
||||
}
|
||||
}
|
||||
fmt.Printf("Extracting %s %s\n", packageName, packageVersion)
|
||||
Unzip("temp.zip", "wyst_tmp")
|
||||
entries, err := os.ReadDir("./wyst_tmp")
|
||||
if err != nil {
|
||||
@@ -61,4 +63,5 @@ func installPackage(packageName, packageVersion string) {
|
||||
if err := os.Remove("temp.zip"); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%s %s Installed\n", packageName, packageVersion)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user