Moved cli and web directory into app dir

This commit is contained in:
Lucas
2026-01-02 12:27:03 -08:00
parent c9f5feb9cb
commit 3fba4355fe
12 changed files with 0 additions and 0 deletions

1
apps/cli/README.md Normal file
View File

@@ -0,0 +1 @@
CLI utility. Currently in development.

21
apps/cli/cli.go Normal file
View File

@@ -0,0 +1,21 @@
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
}

3
apps/cli/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/mustbeperfect/definitive-opensource/cli
go 1.25.5

50
apps/cli/loaders.go Normal file
View File

@@ -0,0 +1,50 @@
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
}

15
apps/cli/main.go Normal file
View File

@@ -0,0 +1,15 @@
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)
}
}

24
apps/cli/models.go Normal file
View File

@@ -0,0 +1,24 @@
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"`
}

48
apps/cli/new/add.go Normal file
View File

@@ -0,0 +1,48 @@
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)
}

29
apps/cli/new/append.go Normal file
View File

@@ -0,0 +1,29 @@
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)
}

View File

@@ -0,0 +1,42 @@
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")
}
}

View File

@@ -0,0 +1,35 @@
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
}

View File

@@ -0,0 +1,35 @@
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
}