From 4effb0f952cf7b31e9cbb040907c3812cf6dce80 Mon Sep 17 00:00:00 2001 From: xplshn Date: Wed, 20 Mar 2024 16:43:30 -0300 Subject: [PATCH] Added -d to the list function, Added --limit to the fsearch function --- fsearch.go | 6 +++--- main.go | 48 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/fsearch.go b/fsearch.go index 1f23bf5..9724299 100644 --- a/fsearch.go +++ b/fsearch.go @@ -11,7 +11,7 @@ import ( ) // fSearch searches for binaries based on the given search term. -func fSearch(searchTerm string) { +func fSearch(searchTerm string, limit int) { // Fetch metadata response, err := http.Get(RMetadataURL) if err != nil { @@ -57,8 +57,8 @@ func fSearch(searchTerm string) { if len(searchResultsSet) == 0 { fmt.Printf("No matching binaries found for '%s'.\n", searchTerm) return - } else if len(searchResultsSet) > 90 { - fmt.Printf("Too many matching binaries (+90. [Limit defined in fsearch.go:60,36]) found for '%s'.\n", searchTerm) + } else if len(searchResultsSet) > limit { + fmt.Printf("Too many matching binaries (+%d. [Use --limit before your query]) found for '%s'.\n", limit, searchTerm) return } diff --git a/main.go b/main.go index dff5697..ff70b3b 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "runtime" + "strconv" ) var ( @@ -82,7 +83,7 @@ Commands: list List all available binaries install, add Install a binary remove, del Remove a binary - update Update binaries, by checking their SHA against the repo's SHA. + update Update binaries, by checking their SHA against the repo's SHA run Run a binary info Show information about a specific binary search Search for a binary - (not all binaries have metadata. Use list to see all binaries) @@ -136,13 +137,17 @@ func main() { } findURLCommand(binaryName) case "list": - binaries, err := listBinaries() - if err != nil { - fmt.Println("Error listing binaries:", err) - os.Exit(1) - } - for _, binary := range binaries { - fmt.Println(binary) + if len(os.Args) > 2 && os.Args[2] == "--described" || os.Args[2] == "-d" { + fSearch("", 99999) // Call fSearch with an empty query and a large limit to list all described binaries + } else { + binaries, err := listBinaries() + if err != nil { + fmt.Println("Error listing binaries:", err) + os.Exit(1) + } + for _, binary := range binaries { + fmt.Println(binary) + } } case "install", "add": // Check if the binary name is provided @@ -206,12 +211,29 @@ func main() { fmt.Printf("Source: %s\n", binaryInfo.Source) } case "search": - query := flag.Arg(1) - if query == "" { - fmt.Println("Usage: bigdl search [query]") - errorOutInsufficientArgs() + limit := 90 + queryIndex := 2 + + if len(os.Args) < queryIndex+1 { + fmt.Println("Usage: bigdl search <--limit||-l [int]> [query]") + os.Exit(1) + } + + if len(os.Args) > 2 && os.Args[queryIndex] == "--limit" || os.Args[queryIndex] == "-l" { + if len(os.Args) > queryIndex+1 { + var err error + limit, err = strconv.Atoi(os.Args[queryIndex+1]) + if err != nil { + errorOut("Error: 'limit' value is not an int.\n") + } + queryIndex += 2 + } else { + errorOut("Error: Missing 'limit' value.\n") + } } - fSearch(query) + + query := os.Args[queryIndex] + fSearch(query, limit) case "update": var programsToUpdate []string if len(os.Args) > 2 {