test in python
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
|
||||||
* text=auto
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
# MacOS
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# VSCode
|
|
||||||
.vscode
|
|
||||||
|
|
||||||
# Output
|
|
||||||
/bin
|
|
||||||
@@ -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,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], ""
|
|
||||||
}
|
|
||||||
-36
@@ -1,36 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func showPackageInfo(packageName string) {
|
|
||||||
url := fmt.Sprintf("https://raw.githubusercontent.com/wyst-lang/index/master/%s/index.json", packageName)
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error fetching package info: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
fmt.Printf("Error: %s\n", resp.Status)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var pkgIndex PackageIndex
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&pkgIndex); err != nil {
|
|
||||||
fmt.Printf("Error decoding package info: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Package: %s\n", packageName)
|
|
||||||
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,98 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PackageVersion struct {
|
|
||||||
Author string `json:"author"`
|
|
||||||
Description string `json:"description"`
|
|
||||||
URL string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PackageIndex struct {
|
|
||||||
Versions map[string]PackageVersion `json:"versions"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func installPackage(packageName, packageVersion string) {
|
|
||||||
url := fmt.Sprintf("https://raw.githubusercontent.com/wyst-lang/index/master/%s/index.json", packageName)
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error fetching package info: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
fmt.Printf("Error: %s\n", resp.Status)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var pkgIndex PackageIndex
|
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&pkgIndex); err != nil {
|
|
||||||
fmt.Printf("Error decoding package info: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if packageVersion == "" {
|
|
||||||
packageVersion = getLatestVersion(pkgIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
pkgVersion, exists := pkgIndex.Versions[packageVersion]
|
|
||||||
if !exists {
|
|
||||||
fmt.Printf("Version %s not found for package %s\n", packageVersion, packageName)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
downloadAndSavePackage(pkgVersion.URL, packageName, packageVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getLatestVersion(pkgIndex PackageIndex) string {
|
|
||||||
var latest string
|
|
||||||
for version := range pkgIndex.Versions {
|
|
||||||
if version > latest {
|
|
||||||
latest = version
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return latest
|
|
||||||
}
|
|
||||||
|
|
||||||
func downloadAndSavePackage(url, packageName, packageVersion string) {
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error downloading package: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
fmt.Printf("Error: %s\n", resp.Status)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
libDir := "lib"
|
|
||||||
if err := os.MkdirAll(libDir, 0755); err != nil {
|
|
||||||
fmt.Printf("Error creating lib directory: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
filename := filepath.Base(url)
|
|
||||||
packageFile := filepath.Join(libDir, filename)
|
|
||||||
out, err := os.Create(packageFile)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error creating package file: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer out.Close()
|
|
||||||
|
|
||||||
if _, err := io.Copy(out, resp.Body); err != nil {
|
|
||||||
fmt.Printf("Error saving package: %v\n", err)
|
|
||||||
} else {
|
|
||||||
fmt.Printf("Package %s version %s downloaded and saved successfully as %s\n", packageName, packageVersion, filename)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-39
@@ -1,39 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
const wpmVersion = "1.0.0"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
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])
|
|
||||||
default:
|
|
||||||
fmt.Println("Unknown command:", command)
|
|
||||||
showHelp()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user