added create, edit, delete
This commit is contained in:
@@ -1,23 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func showHelp() {
|
|
||||||
fmt.Println("wpm - Wyst Package Manager")
|
|
||||||
fmt.Println("Commands:")
|
|
||||||
fmt.Println(" install <package>[:version] - Install a package (version is optional)")
|
|
||||||
fmt.Println(" version - Show the wpm version")
|
|
||||||
fmt.Println(" help - Show this help message")
|
|
||||||
fmt.Println(" info <package> - Show package information (author, description, versions)")
|
|
||||||
}
|
|
||||||
|
|
||||||
func parsePackageArg(arg string) (string, string) {
|
|
||||||
parts := strings.Split(arg, ":")
|
|
||||||
if len(parts) == 2 {
|
|
||||||
return parts[0], parts[1]
|
|
||||||
}
|
|
||||||
return parts[0], ""
|
|
||||||
}
|
|
||||||
+10
-11
@@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
@@ -27,33 +26,33 @@ type PackageIndex struct {
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendRequest(method, url string, jsonBody []byte) Request {
|
func sendRequest(method, url string, jsonBody []byte) (Request, error) {
|
||||||
bodyReader := bytes.NewReader(jsonBody)
|
bodyReader := bytes.NewReader(jsonBody)
|
||||||
req, err := http.NewRequest(method, url, bodyReader)
|
req, err := http.NewRequest(method, url, bodyReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error fetching package info: %v\n", err)
|
return Request{Body: []byte(""), StatusCode: 400}, err
|
||||||
return Request{Body: []byte(""), StatusCode: 402}
|
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
res, err := http.DefaultClient.Do(req)
|
res, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("client: error making http request: %s\n", err)
|
return Request{Body: []byte(""), StatusCode: 400}, err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
resBody, err := ioutil.ReadAll(res.Body)
|
resBody, err := ioutil.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("client: could not read response body: %s\n", err)
|
return Request{Body: []byte(""), StatusCode: 400}, err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
return Request{Body: resBody, StatusCode: res.StatusCode}
|
return Request{Body: resBody, StatusCode: res.StatusCode}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPackage(packageName string) (PackageIndex, error) {
|
func getPackage(packageName string) (PackageIndex, error) {
|
||||||
var pkgidx PackageIndex
|
var pkgidx PackageIndex
|
||||||
jsonBody := []byte(fmt.Sprintf(`{"name": "%s"}`, packageName))
|
jsonBody := []byte(fmt.Sprintf(`{"name": "%s"}`, packageName))
|
||||||
req := sendRequest(http.MethodGet, "http://localhost:3000", jsonBody)
|
req, err := sendRequest(http.MethodGet, "http://localhost:3000", jsonBody)
|
||||||
err := json.Unmarshal(req.Body, &pkgidx)
|
if err != nil {
|
||||||
|
fmt.Printf("Fetching error: %s\n", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(req.Body, &pkgidx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Json Error: ", err)
|
fmt.Println("Json Error: ", err)
|
||||||
return pkgidx, err
|
return pkgidx, err
|
||||||
|
|||||||
@@ -137,4 +137,4 @@ func downloadPackage(repoU, tag string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -45,6 +45,9 @@ func installPackage(packageName, packageVersion string) {
|
|||||||
}
|
}
|
||||||
progress.change(9, "", "Extracting")
|
progress.change(9, "", "Extracting")
|
||||||
Unzip("temp.zip", "wyst_tmp")
|
Unzip("temp.zip", "wyst_tmp")
|
||||||
|
if err := os.RemoveAll("lib/" + packageName); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
entries, err := os.ReadDir("./wyst_tmp")
|
entries, err := os.ReadDir("./wyst_tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
+21
@@ -33,6 +33,27 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
showPackageInfo(os.Args[2])
|
showPackageInfo(os.Args[2])
|
||||||
|
case "create":
|
||||||
|
if len(os.Args) < 3 {
|
||||||
|
fmt.Println("Usage: wpm create <package>")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
createPackage(os.Args[2])
|
||||||
|
|
||||||
|
case "delete":
|
||||||
|
if len(os.Args) < 3 {
|
||||||
|
fmt.Println("Usage: wpm delete <package>")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
deletePackage(os.Args[2])
|
||||||
|
|
||||||
|
case "edit":
|
||||||
|
if len(os.Args) < 3 {
|
||||||
|
fmt.Println("Usage: wpm edit <package>")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
editPackage(os.Args[2])
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Println("Unknown command:", command)
|
fmt.Println("Unknown command:", command)
|
||||||
showHelp()
|
showHelp()
|
||||||
|
|||||||
Reference in New Issue
Block a user