mirror of
https://github.com/mustbeperfect/definitive-opensource.git
synced 2026-04-17 21:54:05 +02:00
Removed go code to start from scratch
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package cli
|
||||
|
||||
import "fmt"
|
||||
|
||||
func Run() error {
|
||||
fmt.Println("Definitive Open Source CLI")
|
||||
fmt.Println("1) Add new project")
|
||||
|
||||
var choice int
|
||||
fmt.Print("Select an option: ")
|
||||
fmt.Scanln(&choice)
|
||||
|
||||
switch choice {
|
||||
case 1:
|
||||
return AddProject()
|
||||
default:
|
||||
fmt.Println("Invalid option")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
module github.com/mustbeperfect/definitive-opensource/cli
|
||||
|
||||
go 1.25.5
|
||||
@@ -1,50 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"definitive-opensource/models"
|
||||
)
|
||||
|
||||
func LoadSubcategories() ([]models.Subcategory, error) {
|
||||
file, err := os.ReadFile("categories.json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var wrapper struct {
|
||||
Subcategories []models.Subcategory `json:"subcategories"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal(file, &wrapper)
|
||||
return wrapper.Subcategories, err
|
||||
}
|
||||
|
||||
func LoadPlatforms() ([]models.Platform, error) {
|
||||
file, err := os.ReadFile("platforms.json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var wrapper struct {
|
||||
Platforms []models.Platform `json:"platforms"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal(file, &wrapper)
|
||||
return wrapper.Platforms, err
|
||||
}
|
||||
|
||||
func LoadTags() ([]models.Tag, error) {
|
||||
file, err := os.ReadFile("tags.json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var wrapper struct {
|
||||
Properties []models.Tag `json:"properties"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal(file, &wrapper)
|
||||
return wrapper.Properties, err
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/definitive-opensource/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := cli.Run(); err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package models
|
||||
|
||||
type Subcategory struct {
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type Platform struct {
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
Name string `json:"name"`
|
||||
RepoURL string `json:"repo_url"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Platforms []string `json:"platforms,omitempty"`
|
||||
Category string `json:"category"`
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"definitive-opencore/data"
|
||||
"definitive-opensource/models"
|
||||
)
|
||||
|
||||
func AddProject() error {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
|
||||
fmt.Print("GitHub repo URL: ")
|
||||
scanner.Scan()
|
||||
repo := strings.TrimSpace(scanner.Text())
|
||||
|
||||
fmt.Print("Project name: ")
|
||||
scanner.Scan()
|
||||
name := strings.TrimSpace(scanner.Text())
|
||||
|
||||
category, err := selectCategory(scanner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
platforms, err := selectPlatforms(scanner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tags, err := selectTags(scanner)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entry := models.Application{
|
||||
Name: name,
|
||||
RepoURL: repo,
|
||||
Category: category,
|
||||
Platforms: platforms,
|
||||
Tags: tags,
|
||||
}
|
||||
|
||||
return data.AppendApplication(entry)
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"definitive-opensource/models"
|
||||
)
|
||||
|
||||
func AppendApplication(app models.Application) error {
|
||||
file, err := os.ReadFile("applications.json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var apps []models.Application
|
||||
if err := json.Unmarshal(file, &apps); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
apps = append(apps, app)
|
||||
|
||||
out, err := json.MarshalIndent(apps, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.WriteFile("applications.json", out, 0644)
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"definitive-opencore/data"
|
||||
)
|
||||
|
||||
func selectCategory(scanner *bufio.Scanner) (string, error) {
|
||||
subs, err := data.LoadSubcategories()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for {
|
||||
fmt.Print("Search category: ")
|
||||
scanner.Scan()
|
||||
query := strings.ToLower(scanner.Text())
|
||||
|
||||
filtered := []string{}
|
||||
for _, s := range subs {
|
||||
if strings.Contains(strings.ToLower(s.Name), query) {
|
||||
filtered = append(filtered, fmt.Sprintf("%s (%s)", s.Name, s.ID))
|
||||
}
|
||||
}
|
||||
|
||||
for i, f := range filtered {
|
||||
fmt.Printf("%d) %s\n", i+1, f)
|
||||
}
|
||||
|
||||
fmt.Print("Select category number: ")
|
||||
var idx int
|
||||
fmt.Scanln(&idx)
|
||||
if idx > 0 && idx <= len(filtered) {
|
||||
return subs[idx-1].ID, nil
|
||||
}
|
||||
|
||||
fmt.Println("Invalid selection, try again")
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
|
||||
"definitive-opencore/data"
|
||||
)
|
||||
|
||||
func selectPlatforms(scanner *bufio.Scanner) ([]string, error) {
|
||||
platforms, err := data.LoadPlatforms()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
selected := []string{}
|
||||
|
||||
for {
|
||||
fmt.Println("Select platforms (0 to finish):")
|
||||
for i, p := range platforms {
|
||||
fmt.Printf("%d) %s\n", i+1, p.Name)
|
||||
}
|
||||
|
||||
var idx int
|
||||
fmt.Scanln(&idx)
|
||||
if idx == 0 {
|
||||
break
|
||||
}
|
||||
if idx > 0 && idx <= len(platforms) {
|
||||
selected = append(selected, platforms[idx-1].ID)
|
||||
}
|
||||
}
|
||||
|
||||
return selected, nil
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
|
||||
"definitive-opencore/data"
|
||||
)
|
||||
|
||||
func selectTags(scanner *bufio.Scanner) ([]string, error) {
|
||||
tags, err := data.LoadTags()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
selected := []string{}
|
||||
|
||||
for {
|
||||
fmt.Println("Select tags (0 to finish):")
|
||||
for i, t := range tags {
|
||||
fmt.Printf("%d) %s\n", i+1, t.Name)
|
||||
}
|
||||
|
||||
var idx int
|
||||
fmt.Scanln(&idx)
|
||||
if idx == 0 {
|
||||
break
|
||||
}
|
||||
if idx > 0 && idx <= len(tags) {
|
||||
selected = append(selected, tags[idx-1].ID)
|
||||
}
|
||||
}
|
||||
|
||||
return selected, nil
|
||||
}
|
||||
Reference in New Issue
Block a user