Skip to content

Commit

Permalink
Added -d to the list function, Added --limit to the fsearch function
Browse files Browse the repository at this point in the history
  • Loading branch information
xplshn committed Mar 20, 2024
1 parent dd96f28 commit 4effb0f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
6 changes: 3 additions & 3 deletions fsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
48 changes: 35 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
)

var (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4effb0f

Please sign in to comment.