Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e27aa595d2 | ||
|
|
049a6904b0 | ||
|
|
ad91d6205e |
@@ -1,2 +0,0 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
|
||||||
* text=auto
|
|
||||||
+5
-11
@@ -1,11 +1,5 @@
|
|||||||
# MacOS
|
dist/
|
||||||
.DS_Store
|
build/
|
||||||
|
lib/
|
||||||
# VSCode
|
package.json
|
||||||
.vscode
|
main.spec
|
||||||
|
|
||||||
# Output
|
|
||||||
/bin
|
|
||||||
|
|
||||||
# Lib
|
|
||||||
/lib
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# Project variables
|
|
||||||
BINARY_NAME = wpm
|
|
||||||
SOURCE_DIR = src
|
|
||||||
OUTPUT_DIR = bin
|
|
||||||
|
|
||||||
# Go commands
|
|
||||||
BUILD_CMD = go build -o $(OUTPUT_DIR)/$(BINARY_NAME) $(SOURCE_DIR)/*.go
|
|
||||||
RUN_CMD = go run $(SOURCE_DIR)/*.go
|
|
||||||
|
|
||||||
# Targets
|
|
||||||
.PHONY: all build run clean
|
|
||||||
|
|
||||||
# Default target
|
|
||||||
all: build
|
|
||||||
|
|
||||||
# Build the project
|
|
||||||
build:
|
|
||||||
@echo "Building the project..."
|
|
||||||
@mkdir -p $(OUTPUT_DIR)
|
|
||||||
@$(BUILD_CMD)
|
|
||||||
@echo "Build complete!"
|
|
||||||
|
|
||||||
# Run the project using `go run`
|
|
||||||
run:
|
|
||||||
@echo "Running the project..."
|
|
||||||
@$(RUN_CMD)
|
|
||||||
|
|
||||||
# Clean the output directory
|
|
||||||
clean:
|
|
||||||
@echo "Cleaning up..."
|
|
||||||
@rm -rf $(OUTPUT_DIR)
|
|
||||||
@echo "Clean complete!"
|
|
||||||
@@ -1,25 +1,2 @@
|
|||||||
# wyst-package-manager
|
# wyst-package-manager
|
||||||
A package manager for the programming language Wyst
|
A package manager for the programming language Wyst
|
||||||
|
|
||||||
|
|
||||||
## Usage:
|
|
||||||
|
|
||||||
### Installing packages (version is optional)
|
|
||||||
```console
|
|
||||||
wpm install <package>[:version]
|
|
||||||
```
|
|
||||||
|
|
||||||
### Version
|
|
||||||
```console
|
|
||||||
wpm version
|
|
||||||
```
|
|
||||||
|
|
||||||
### Help
|
|
||||||
```console
|
|
||||||
wpm help
|
|
||||||
```
|
|
||||||
### Obtaining information from a package
|
|
||||||
```console
|
|
||||||
wpm info <package>
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
module github.com/wyst-lang/wpm
|
|
||||||
|
|
||||||
go 1.22.0
|
|
||||||
|
|
||||||
require (
|
|
||||||
golang.org/x/sys v0.20.0 // indirect
|
|
||||||
golang.org/x/term v0.20.0 // direct
|
|
||||||
)
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
|
||||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
|
|
||||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
sudo cp -rf . ~/wpm
|
|
||||||
cd ~/wpm
|
|
||||||
go build -o bin/wpm src/*.go
|
|
||||||
sudo cp bin/wpm /usr/local/bin/
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
@echo off
|
|
||||||
cd %~dp0
|
|
||||||
where go >nul 2>&1
|
|
||||||
if %errorlevel% neq 0 (
|
|
||||||
echo please install go: https://go.dev/doc/install
|
|
||||||
start https://go.dev/doc/install
|
|
||||||
exit /b 1
|
|
||||||
) else (
|
|
||||||
@echo off
|
|
||||||
xcopy /s /e /i /h /y . "%USERPROFILE%\wpm"
|
|
||||||
cd /d "%USERPROFILE%\wpm\src"
|
|
||||||
go build -o ..\wpm.exe
|
|
||||||
copy ..\wpm.exe C:\Windows\System32
|
|
||||||
)
|
|
||||||
|
|
||||||
pause
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import urllib
|
||||||
|
import urllib.parse
|
||||||
|
import requests
|
||||||
|
import os
|
||||||
|
from json import dump
|
||||||
|
import shutil
|
||||||
|
import zipfile
|
||||||
|
from sys import argv
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
import re
|
||||||
|
|
||||||
|
def extract(zip_file, pkgName):
|
||||||
|
os.makedirs("tmp", exist_ok=True)
|
||||||
|
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
|
||||||
|
zip_ref.extractall(path="tmp")
|
||||||
|
old_folder_name = os.listdir("tmp")[0]
|
||||||
|
final_destination = 'lib/'+pkgName
|
||||||
|
try:shutil.rmtree(final_destination)
|
||||||
|
except:pass
|
||||||
|
shutil.move(os.path.join("tmp", old_folder_name), final_destination)
|
||||||
|
shutil.rmtree('tmp')
|
||||||
|
|
||||||
|
def downloadRelease(pkgName, repo, tag):
|
||||||
|
if tag=='latest':
|
||||||
|
tag = requests.get(os.path.join('https://api.github.com/repos',
|
||||||
|
str(urlparse(repo).path).removeprefix('/'),
|
||||||
|
'releases/latest'),
|
||||||
|
headers={"Accept": "application/vnd.github+json"}).json()['tag_name']
|
||||||
|
url = os.path.join(repo, f'archive/refs/tags/{tag}.zip')
|
||||||
|
urllib.request.urlretrieve(url, "temp.zip")
|
||||||
|
extract('temp.zip', pkgName)
|
||||||
|
os.remove('temp.zip')
|
||||||
|
|
||||||
|
def installPackage(packageName, packageVersion='latest'):
|
||||||
|
print(f"Indexing package {packageName}")
|
||||||
|
req = requests.get("http://localhost:3000", json={'name': packageName})
|
||||||
|
data = req.json()
|
||||||
|
if req.status_code==200:
|
||||||
|
print(f"Downloading package {packageName}")
|
||||||
|
downloadRelease(packageName, data['repo'], packageVersion)
|
||||||
|
print(f"Done")
|
||||||
|
else:
|
||||||
|
print(f'Error ({packageName}): {data["message"]}')
|
||||||
|
quit(1)
|
||||||
|
|
||||||
|
def verify_repo(n) -> str:
|
||||||
|
re_match = re.match(r'^https://(github.com)/[a-zA-Z0-9\-]+/[a-zA-Z0-9\-]+', n)
|
||||||
|
if re_match:
|
||||||
|
return str(re_match.group())
|
||||||
|
else:
|
||||||
|
print(f'Error: invalid repo')
|
||||||
|
quit(1)
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
|
argl = len(argv)
|
||||||
|
if argl > 1:
|
||||||
|
match argv[1]:
|
||||||
|
case "install":
|
||||||
|
if argl > 2:
|
||||||
|
for pkg in argv[2::]:
|
||||||
|
package = pkg.split('@')
|
||||||
|
if len(package) == 2:
|
||||||
|
installPackage(package[0], package[1])
|
||||||
|
else:
|
||||||
|
installPackage(pkg)
|
||||||
|
case "init":
|
||||||
|
pkg_json = {
|
||||||
|
'name': str(os.getcwd().split('/')[-1].split('\\')[-1]),
|
||||||
|
'repo': verify_repo(input("link to the repository (required) "))
|
||||||
|
}
|
||||||
|
if not os.path.exists:
|
||||||
|
os.mkdir("lib")
|
||||||
|
with open('package.json', 'w')as f:
|
||||||
|
dump(pkg_json, f)
|
||||||
|
case _:...
|
||||||
-149
@@ -1,149 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// const URL = "http://localhost:3000"
|
|
||||||
const URL = "https://pms-xdib.onrender.com"
|
|
||||||
|
|
||||||
func showHelp() {
|
|
||||||
fmt.Println("wpm - Wyst Package Manager")
|
|
||||||
fmt.Println("Commands:")
|
|
||||||
fmt.Println(" install <package>[:version] - Install a package (version is optional)")
|
|
||||||
fmt.Println(" create <package> - Create a package")
|
|
||||||
fmt.Println(" edit <package> - Edit a package")
|
|
||||||
fmt.Println(" delete <package> - Delete a package")
|
|
||||||
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], ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func createPackage(packageName string) {
|
|
||||||
var psw string
|
|
||||||
var pswV string
|
|
||||||
var repo string
|
|
||||||
var version string
|
|
||||||
fmt.Printf("Enter the password for %s: ", packageName)
|
|
||||||
ReadPassword(&psw)
|
|
||||||
fmt.Printf("Verify the password for %s: ", packageName)
|
|
||||||
ReadPassword(&pswV)
|
|
||||||
if psw != pswV {
|
|
||||||
fmt.Printf("Passwords do not match\n\r")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("Enter the repo for %s: ", packageName)
|
|
||||||
fmt.Scanln(&repo)
|
|
||||||
fmt.Printf("Enter the latest version for %s: ", packageName)
|
|
||||||
fmt.Scanln(&version)
|
|
||||||
fmt.Println()
|
|
||||||
jsonBody := []byte(fmt.Sprintf(`{"name": "%v", "psw": "%v", "repo": "%v", "latest": "%v"}`, packageName, psw, repo, version))
|
|
||||||
req, err := sendRequest(http.MethodPost, URL, jsonBody)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = getMessage(req)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error: %v\n\r", err)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Done\n\r")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func editPackage(packageName string) {
|
|
||||||
pkgidx, err := getPackage(packageName)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var psw string
|
|
||||||
var repo string = pkgidx.Repo
|
|
||||||
var version string = pkgidx.Latest
|
|
||||||
var newPsw string
|
|
||||||
var newPackageName string = packageName
|
|
||||||
|
|
||||||
fmt.Printf("\rEnter the password for %s: ", packageName)
|
|
||||||
ReadPassword(&psw)
|
|
||||||
newPsw = psw
|
|
||||||
|
|
||||||
for true {
|
|
||||||
clear()
|
|
||||||
fmt.Printf("Choose what you want to modify\n\r")
|
|
||||||
fmt.Printf(" 1 -> package name : %s\n\r", newPackageName)
|
|
||||||
fmt.Printf(" 2 -> password : %s\n\r", newPsw)
|
|
||||||
fmt.Printf(" 3 -> repo : %s\n\r", repo)
|
|
||||||
fmt.Printf(" 4 -> latest version: %s\n\r", version)
|
|
||||||
fmt.Printf("Type in 'quit'/'q'/'exit' to discard your changes\n\r")
|
|
||||||
fmt.Printf("Type in anything else to confirm your changes\n\r")
|
|
||||||
var option string
|
|
||||||
fmt.Print("\n> ")
|
|
||||||
fmt.Scanln(&option)
|
|
||||||
switch option {
|
|
||||||
case "1":
|
|
||||||
fmt.Printf("Enter the new name for for %s: ", packageName)
|
|
||||||
fmt.Scanln(&newPackageName)
|
|
||||||
case "2":
|
|
||||||
fmt.Printf("Enter the new password for %s: ", packageName)
|
|
||||||
ReadPassword(&newPsw)
|
|
||||||
case "3":
|
|
||||||
fmt.Printf("Enter the repo for %s: ", packageName)
|
|
||||||
fmt.Scanln(&repo)
|
|
||||||
case "4":
|
|
||||||
fmt.Printf("Enter the latest version for %s: ", packageName)
|
|
||||||
fmt.Scanln(&version)
|
|
||||||
case "q":
|
|
||||||
return
|
|
||||||
case "quit":
|
|
||||||
return
|
|
||||||
case "exit":
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
jsonBody := []byte(fmt.Sprintf(`{ "new": {"name": "%v", "psw": "%v", "latest": "%v", "repo": "%v"}, "name": "%v", "psw": "%v"}`, newPackageName, newPsw, version, repo, packageName, psw))
|
|
||||||
req, err := sendRequest(http.MethodPut, URL, jsonBody)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error while editing %s: %v", packageName, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = getMessage(req)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error: %v\n\r", err)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Done\n\r")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func deletePackage(packageName string) {
|
|
||||||
fmt.Printf("Enter the password for %s: ", packageName)
|
|
||||||
var psw string
|
|
||||||
ReadPassword(&psw)
|
|
||||||
jsonBody := []byte(fmt.Sprintf(`{"name": "%s", "psw": "%v"}`, packageName, psw))
|
|
||||||
req, err := sendRequest(http.MethodDelete, URL, jsonBody)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = getMessage(req)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error: %v\n\r", err)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Done\n\r")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Request struct {
|
|
||||||
Body []byte
|
|
||||||
StatusCode int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Package struct {
|
|
||||||
Author string `json:"author"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PackageIndex struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Repo string `json:"repo"`
|
|
||||||
Latest string `json:"latest"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Message struct {
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func sendRequest(method, url string, jsonBody []byte) (Request, error) {
|
|
||||||
bodyReader := bytes.NewReader(jsonBody)
|
|
||||||
req, err := http.NewRequest(method, url, bodyReader)
|
|
||||||
if err != nil {
|
|
||||||
return Request{Body: []byte(""), StatusCode: 400}, err
|
|
||||||
}
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
res, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return Request{Body: []byte(""), StatusCode: 400}, err
|
|
||||||
}
|
|
||||||
defer res.Body.Close()
|
|
||||||
resBody, err := ioutil.ReadAll(res.Body)
|
|
||||||
if err != nil {
|
|
||||||
return Request{Body: []byte(""), StatusCode: 400}, err
|
|
||||||
}
|
|
||||||
return Request{Body: resBody, StatusCode: res.StatusCode}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPackage(packageName string) (PackageIndex, error) {
|
|
||||||
var pkgidx PackageIndex
|
|
||||||
jsonBody := []byte(fmt.Sprintf(`{"name": "%s"}`, packageName))
|
|
||||||
req, err := sendRequest(http.MethodGet, URL, jsonBody)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Fetching error: %s\n", err)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(req.Body, &pkgidx)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Json Error: ", err)
|
|
||||||
return pkgidx, err
|
|
||||||
}
|
|
||||||
if req.StatusCode != 200 {
|
|
||||||
return pkgidx, fmt.Errorf(pkgidx.Message)
|
|
||||||
}
|
|
||||||
return pkgidx, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMessage(req Request) error {
|
|
||||||
var msg Message
|
|
||||||
err := json.Unmarshal(req.Body, &msg)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("JsonError: %v", err)
|
|
||||||
}
|
|
||||||
if msg.Message != "ok" {
|
|
||||||
return fmt.Errorf(msg.Message)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"archive/zip"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Author struct {
|
|
||||||
Login string `json:"login"`
|
|
||||||
ID int `json:"id"`
|
|
||||||
NodeID string `json:"node_id"`
|
|
||||||
AvatarURL string `json:"avatar_url"`
|
|
||||||
GravatarID string `json:"gravatar_id"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
HTMLURL string `json:"html_url"`
|
|
||||||
FollowersURL string `json:"followers_url"`
|
|
||||||
FollowingURL string `json:"following_url"`
|
|
||||||
GistsURL string `json:"gists_url"`
|
|
||||||
StarredURL string `json:"starred_url"`
|
|
||||||
SubscriptionsURL string `json:"subscriptions_url"`
|
|
||||||
OrganizationsURL string `json:"organizations_url"`
|
|
||||||
ReposURL string `json:"repos_url"`
|
|
||||||
EventsURL string `json:"events_url"`
|
|
||||||
ReceivedEventsURL string `json:"received_events_url"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
SiteAdmin bool `json:"site_admin"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define a struct for the Release
|
|
||||||
type Release struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
AssetsURL string `json:"assets_url"`
|
|
||||||
UploadURL string `json:"upload_url"`
|
|
||||||
HTMLURL string `json:"html_url"`
|
|
||||||
ID int `json:"id"`
|
|
||||||
Author Author `json:"author"`
|
|
||||||
NodeID string `json:"node_id"`
|
|
||||||
TagName string `json:"tag_name"`
|
|
||||||
TargetCommitish string `json:"target_commitish"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Draft bool `json:"draft"`
|
|
||||||
Prerelease bool `json:"prerelease"`
|
|
||||||
CreatedAt string `json:"created_at"`
|
|
||||||
PublishedAt string `json:"published_at"`
|
|
||||||
Assets []interface{} `json:"assets"` // Assuming assets is an array of unknown types
|
|
||||||
TarballURL string `json:"tarball_url"`
|
|
||||||
ZipballURL string `json:"zipball_url"`
|
|
||||||
Body string `json:"body"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func Unzip(src, dest string) error {
|
|
||||||
r, err := zip.OpenReader(src)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err := r.Close(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
os.MkdirAll(dest, 0755)
|
|
||||||
|
|
||||||
// Closure to address file descriptors issue with all the deferred .Close() methods
|
|
||||||
extractAndWriteFile := func(f *zip.File) error {
|
|
||||||
rc, err := f.Open()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err := rc.Close(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
path := filepath.Join(dest, f.Name)
|
|
||||||
|
|
||||||
// Check for ZipSlip (Directory traversal)
|
|
||||||
if !strings.HasPrefix(path, filepath.Clean(dest)+string(os.PathSeparator)) {
|
|
||||||
return fmt.Errorf("illegal file path: %s", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.FileInfo().IsDir() {
|
|
||||||
os.MkdirAll(path, f.Mode())
|
|
||||||
} else {
|
|
||||||
os.MkdirAll(filepath.Dir(path), f.Mode())
|
|
||||||
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err := f.Close(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err = io.Copy(f, rc)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, f := range r.File {
|
|
||||||
err := extractAndWriteFile(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func downloadPackage(repoU, tag string) error {
|
|
||||||
resp, err := http.Get(fmt.Sprintf("https://github.com/%s/archive/refs/tags/%s.zip", strings.Trim(repoU, "/"), tag))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
out, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error reading body:", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ioutil.WriteFile("temp.zip", out, 0644)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error writing file:", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
func showPackageInfo(packageName string) {
|
|
||||||
progress := ProgressBar{total: 4, length: 20}
|
|
||||||
progress.change(3, "", "Fetching")
|
|
||||||
pkgidx, err := getPackage(packageName)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("\nError getting repo URL: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
progress.clean()
|
|
||||||
|
|
||||||
// indexURL, err := findIndexURL(repoURL)
|
|
||||||
// if err != nil {
|
|
||||||
// fmt.Printf("Error finding index URL: %v\n", err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pkgIndex, err := fetchPackageIndex(indexURL)
|
|
||||||
// if err != nil {
|
|
||||||
// fmt.Printf("Error fetching package index: %v\n", err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
fmt.Printf("Package: %s\n", packageName)
|
|
||||||
fmt.Printf("Repo: %s\n", pkgidx.Repo)
|
|
||||||
fmt.Printf("Version: %s\n", pkgidx.Latest)
|
|
||||||
// for version, info := range pkgIndex.Versions {
|
|
||||||
// fmt.Printf("Version: %s\n", version)
|
|
||||||
// fmt.Printf(" Author: %s\n", info.Author)
|
|
||||||
// fmt.Printf(" Description: %s\n", info.Description)
|
|
||||||
// fmt.Println()
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func installPackage(packageName, packageVersion string) {
|
|
||||||
progress := ProgressBar{total: 10, length: 20, enabled: true}
|
|
||||||
progress.change(1, "", "Fetching")
|
|
||||||
pkgidx, err := getPackage(packageName)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error getting repo URL: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
repoU, err := url.Parse(pkgidx.Repo)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error parsing repo URL: %s\n", err)
|
|
||||||
}
|
|
||||||
if packageVersion == "" {
|
|
||||||
packageVersion = pkgidx.Latest
|
|
||||||
progress.change(3, "", fmt.Sprintf("Using version %s", packageVersion))
|
|
||||||
}
|
|
||||||
progress.change(6, "", "Downloading")
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
progress.change(9, "", "Extracting")
|
|
||||||
Unzip("temp.zip", "wyst_tmp")
|
|
||||||
if err := os.RemoveAll("lib/" + packageName); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
entries, err := os.ReadDir("./wyst_tmp")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if err := os.Mkdir("lib", os.ModePerm); err != nil {
|
|
||||||
ERR := fmt.Sprintf("%s", err)
|
|
||||||
if !strings.Contains(strings.ToLower(ERR), "file exists") {
|
|
||||||
panic(ERR)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, e := range entries {
|
|
||||||
os.Rename("wyst_tmp/"+e.Name(), "lib/"+packageName)
|
|
||||||
}
|
|
||||||
if err := os.RemoveAll("wyst_tmp"); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if err := os.Remove("temp.zip"); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
progress.change(10, "", "Installed")
|
|
||||||
progress.clean()
|
|
||||||
fmt.Printf("%s %s Installed\n\n", packageName, packageVersion)
|
|
||||||
}
|
|
||||||
-61
@@ -1,61 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
const wpmVersion = "1.0.0"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println()
|
|
||||||
if len(os.Args) < 2 {
|
|
||||||
showHelp()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
command := os.Args[1]
|
|
||||||
switch command {
|
|
||||||
case "install":
|
|
||||||
if len(os.Args) < 3 {
|
|
||||||
fmt.Println("Usage: wpm install <package>[:version]")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
packageName, packageVersion := parsePackageArg(os.Args[2])
|
|
||||||
installPackage(packageName, packageVersion)
|
|
||||||
case "version":
|
|
||||||
fmt.Println("wpm version", wpmVersion)
|
|
||||||
case "help":
|
|
||||||
showHelp()
|
|
||||||
case "info":
|
|
||||||
if len(os.Args) < 3 {
|
|
||||||
fmt.Println("Usage: wpm info <package>")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
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:
|
|
||||||
fmt.Println("Unknown command:", command)
|
|
||||||
showHelp()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"golang.org/x/term"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ProgressBar struct {
|
|
||||||
total int
|
|
||||||
length int
|
|
||||||
last_suffix int
|
|
||||||
enabled bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (prb *ProgressBar) change(amount int, prefix, suffix string) {
|
|
||||||
if prb.enabled {
|
|
||||||
percent := float64(amount) / float64(prb.total)
|
|
||||||
filledLength := int(float64(prb.length) * percent)
|
|
||||||
fill := "█"
|
|
||||||
end := "█"
|
|
||||||
if amount == prb.total {
|
|
||||||
end = "█"
|
|
||||||
}
|
|
||||||
for len(suffix) < prb.last_suffix {
|
|
||||||
suffix += " "
|
|
||||||
}
|
|
||||||
bar := strings.Repeat(fill, filledLength) + end + strings.Repeat("-", (prb.length-filledLength))
|
|
||||||
fmt.Printf("\r%s [%s] %s", prefix, bar, suffix)
|
|
||||||
// if amount == prb.total {
|
|
||||||
// fmt.Println()
|
|
||||||
// }
|
|
||||||
prb.last_suffix = len(suffix) + 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (prb ProgressBar) clean() {
|
|
||||||
if prb.enabled {
|
|
||||||
fmt.Printf("\r" + strings.Repeat(" ", prb.last_suffix+prb.length+2) + "\r")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadPassword(buff *string) error {
|
|
||||||
safeChar := "*"
|
|
||||||
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer term.Restore(int(os.Stdin.Fd()), oldState)
|
|
||||||
for true {
|
|
||||||
b := make([]byte, 1)
|
|
||||||
_, err = os.Stdin.Read(b)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
chr := string(b[0])
|
|
||||||
if chr == "\r" || chr == "\n" {
|
|
||||||
fmt.Printf("\n\r")
|
|
||||||
return nil
|
|
||||||
} else if chr == "\b" || b[0] == 127 {
|
|
||||||
if len(*buff) > 0 {
|
|
||||||
fmt.Print("\033[1D \033[1D")
|
|
||||||
*buff = string(*buff)[:len(*buff)-1]
|
|
||||||
}
|
|
||||||
} else if b[0] == 3 {
|
|
||||||
os.Exit(0)
|
|
||||||
} else {
|
|
||||||
*buff += chr
|
|
||||||
if safeChar == "off" {
|
|
||||||
fmt.Print(chr)
|
|
||||||
} else {
|
|
||||||
fmt.Print(safeChar)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func clear() {
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "windows":
|
|
||||||
cmd := exec.Command("cmd", "/c", "cls")
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Run()
|
|
||||||
default: // Unix-like systems
|
|
||||||
cmd := exec.Command("clear")
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Run()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user