The definitive list of the best of (consumer facing) open source.
Populated CLI with initial GO
Lucasbfcf8d271b64
diff --git a/cli/README.md b/cli/README.mdindex 56bf754..44c4139 100644--- a/cli/README.md+++ b/cli/README.md@@ -1 +1 @@-The future CLI companion for definitive-opensource.\ No newline at end of file+CLI utility. Currently in development.\ No newline at end of filediff --git a/cli/cli.go b/cli/cli.gonew file mode 100644index 0000000..6eecd6c--- /dev/null+++ b/cli/cli.go@@ -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+}diff --git a/cli/loaders.go b/cli/loaders.gonew file mode 100644index 0000000..9e180f2--- /dev/null+++ b/cli/loaders.go@@ -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+}diff --git a/cli/main.go b/cli/main.goindex 7905807..b01d2cc 100644--- a/cli/main.go+++ b/cli/main.go@@ -1,5 +1,15 @@package main-func main() {+import (+ "fmt"+ "os"++ "definitive-opensource/cli"+)+func main() {+ if err := cli.Run(); err != nil {+ fmt.Println("Error:", err)+ os.Exit(1)+ }}diff --git a/cli/models.go b/cli/models.gonew file mode 100644index 0000000..2bc5396--- /dev/null+++ b/cli/models.go@@ -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"`+}diff --git a/cli/new/add.go b/cli/new/add.gonew file mode 100644index 0000000..378abf6--- /dev/null+++ b/cli/new/add.go@@ -0,0 +1,48 @@+package cli++import (+ "bufio"+ "fmt"+ "os"+ "strings"++ "definitive-opensource/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)+}diff --git a/cli/new/append.go b/cli/new/append.gonew file mode 100644index 0000000..019bfcc--- /dev/null+++ b/cli/new/append.go@@ -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)+}diff --git a/cli/new/select_category.go b/cli/new/select_category.gonew file mode 100644index 0000000..b2e85ab--- /dev/null+++ b/cli/new/select_category.go@@ -0,0 +1,42 @@+package cli++import (+ "bufio"+ "fmt"+ "strings"++ "definitive-opensource/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")+ }+}diff --git a/cli/new/select_platforms.go b/cli/new/select_platforms.gonew file mode 100644index 0000000..06a6c02--- /dev/null+++ b/cli/new/select_platforms.go@@ -0,0 +1,35 @@+package cli++import (+ "bufio"+ "fmt"++ "definitive-opensource/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+}diff --git a/cli/new/select_tags.go b/cli/new/select_tags.gonew file mode 100644index 0000000..198a5ad--- /dev/null+++ b/cli/new/select_tags.go@@ -0,0 +1,35 @@+package cli++import (+ "bufio"+ "fmt"++ "definitive-opensource/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+}