Skip to content

Commit

Permalink
Merge pull request #38 from xplshn/dev
Browse files Browse the repository at this point in the history
1.4 is out!
  • Loading branch information
xplshn committed Mar 9, 2024
2 parents b8cd032 + 7bfde3d commit ac681d1
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 245 deletions.
Binary file modified bigdl
100644 → 100755
Binary file not shown.
6 changes: 2 additions & 4 deletions findURL.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ package main
import (
"fmt"
"net/http"
"os"
)

// findURLCommand returns the URL for the specified binary. We do not use info.go for this because unmarshalling such big files is slower than pinging to see which exists
func findURLCommand(binaryName string) {
url, err := findURL(binaryName)
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
errorOut("Error: %v\n", err)
}

fmt.Println(url)
Expand All @@ -32,5 +30,5 @@ func findURL(binaryName string) (string, error) {
}
}

return "", fmt.Errorf("Binary's SOURCE_URL was not found")
return "", fmt.Errorf("Error: Binary's SOURCE_URL was not found.")
}
3 changes: 1 addition & 2 deletions fsearch.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// fsearch.go // this file implements the search option

package main

import (
Expand Down Expand Up @@ -59,7 +58,7 @@ func fSearch(searchTerm string) {
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:63:36,37]) found for '%s'.\n", searchTerm)
fmt.Printf("Too many matching binaries (+90. [Limit defined in fsearch.go:60,36]) found for '%s'.\n", searchTerm)
return
}

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/xplshn/bigdl

go 1.21.6
go 1.22.0

require github.com/schollz/progressbar/v3 v3.14.2

require (
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/schollz/progressbar/v3 v3.14.2 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
)
52 changes: 3 additions & 49 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,67 +1,21 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabe565/go-spinners v1.0.1 h1:E8C4qV+TxyvSPpIqAjE6gPNsZ9bqb8aHPiVxMPwPBk0=
github.com/gabe565/go-spinners v1.0.1/go.mod h1:xB3UuNr3Rb97UoOcX7Irq5UWFhpPuieXUMnZ+KsIXck=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg=
github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM=
github.com/schollz/progressbar v1.0.0/go.mod h1:/l9I7PC3L3erOuz54ghIRKUEFcosiWfLvJv+Eq26UMs=
github.com/schollz/progressbar/v3 v3.14.2 h1:EducH6uNLIWsr560zSV1KrTeUb/wZGAHqyMFIEa99ks=
github.com/schollz/progressbar/v3 v3.14.2/go.mod h1:aQAZQnhF4JGFtRJiw/eobaXpsqpVQAftEQ+hLGXaRc4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
83 changes: 52 additions & 31 deletions helperFunctions.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// helperFunctions.go // This file contains commonly used functions //>
// TODO: Add *PROPER* error handling in the truncate functions. Ensure escape sequences are correctly handled?
package main

import (
Expand All @@ -18,6 +17,8 @@ import (
"syscall"
)

// TODO: Add *PROPER* error handling in the truncate functions. Ensure escape sequences are correctly handled?

// signalHandler sets up a channel to listen for interrupt signals and returns a function
// that can be called to check if an interrupt has been received.
func signalHandler(ctx context.Context, cancel context.CancelFunc) (func() bool, error) {
Expand Down Expand Up @@ -93,27 +94,7 @@ func fetchBinaryFromURL(url, destination string) error {
return fmt.Errorf("failed to fetch binary from %s. HTTP status code: %d", url, resp.StatusCode)
}

// Create a progress bar
var bar *progressbar.ProgressBar
if useProgressBar {
bar = progressbar.NewOptions(int(resp.ContentLength),
progressbar.OptionClearOnFinish(),
progressbar.OptionFullWidth(),
progressbar.OptionShowBytes(true),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "=",
SaucerHead: ">",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}),
)
} else {
bar = progressbar.NewOptions(-1,
progressbar.OptionSetVisibility(false), // Couldn't make update.go work well enough with it.
progressbar.OptionSpinnerType(9), // Type 9 spinner (Classic BSD styled spinner; "|/-\").
)
}
bar := spawnProgressBar(resp.ContentLength)

// Write the binary to the temporary file with progress bar
_, err = io.Copy(io.MultiWriter(out, bar), resp.Body)
Expand Down Expand Up @@ -144,7 +125,8 @@ func fetchBinaryFromURL(url, destination string) error {
fmt.Printf("failed to remove temporary file: %v\n", err)
}
}
fmt.Println("\r\033[K")

//fmt.Printf("\033[A")
return nil
}

Expand Down Expand Up @@ -188,12 +170,12 @@ func copyFile(src, dst string) error {

// removeDuplicates removes duplicate elements from the input slice.
func removeDuplicates(input []string) []string {
seen := make(map[string]struct{})
var unique []string
for _, s := range input {
if _, ok := seen[s]; !ok {
seen[s] = struct{}{}
unique = append(unique, s)
seen := make(map[string]bool)
unique := []string{}
for _, entry := range input {
if _, value := seen[entry]; !value {
seen[entry] = true
unique = append(unique, entry)
}
}
return unique
Expand Down Expand Up @@ -262,6 +244,24 @@ func listFilesInDir(dir string) ([]string, error) {
return files, nil
}

func spawnProgressBar(contentLength int64) *progressbar.ProgressBar {
if useProgressBar {
return progressbar.NewOptions(int(contentLength),
progressbar.OptionClearOnFinish(),
progressbar.OptionFullWidth(),
progressbar.OptionShowBytes(true),
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "=",
SaucerHead: ">",
SaucerPadding: " ",
BarStart: "[",
BarEnd: "]",
}),
)
}
return progressbar.NewOptions(0, progressbar.OptionClearOnFinish()) // A dummy
}

// sanitizeString removes certain punctuation from the end of the string and converts it to lower case.
func sanitizeString(s string) string {
// Define the punctuation to remove
Expand All @@ -280,6 +280,24 @@ func sanitizeString(s string) string {
return s
}

// errorEncoder generates a unique error code based on the sum of ASCII values of the error message.
func errorEncoder(format string, args ...interface{}) int {
formattedErrorMessage := fmt.Sprintf(format, args...)

var sum int
for _, char := range formattedErrorMessage {
sum += int(char)
}
errorCode := sum % 256
fmt.Fprint(os.Stderr, formattedErrorMessage)
return errorCode
}

// errorOut prints the error message to stderr and exits the program with the error code generated by errorEncoder.
func errorOut(format string, args ...interface{}) {
os.Exit(errorEncoder(format, args...))
}

// GetTerminalWidth attempts to determine the width of the terminal.
// It first tries using "stty size", then "tput cols", and finally falls back to 80 columns.
func getTerminalWidth() int {
Expand Down Expand Up @@ -333,8 +351,11 @@ func truncateSprintf(format string, a ...interface{}) string {

// truncatePrintf is a drop-in replacement for fmt.Printf that truncates the input string if it exceeds a certain length.
func truncatePrintf(format string, a ...interface{}) (n int, err error) {
formatted := truncateSprintf(format, a...)
return fmt.Print(formatted)
if disableTruncation {
return fmt.Print(fmt.Sprintf(format, a...))
} else {
return fmt.Print(truncateSprintf(format, a...))
}
}

// NOTE: Both truncate functions will remove the escape sequences of truncated lines, and sometimes break them in half because of the truncation. Avoid using escape sequences with truncate functions, as it is UNSAFE.
32 changes: 22 additions & 10 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"path/filepath"
)

func installCommand(binaryName string, messages ...string) error {
func installCommand(binaryName string, installMessage ...string) error {
installPath := filepath.Join(InstallDir, binaryName)

// Use ReturnCachedFile to check for a cached file
if installUseCache {
cachedFile, errCode := ReturnCachedFile(binaryName)
if errCode == 0 {
cachedFile, err := ReturnCachedFile(binaryName)
if err == 0 {
// If the cached file exists, use it
fmt.Printf("\r\033[KUsing cached file: %s\n", cachedFile)
// Copy the cached file to the install path
Expand All @@ -26,20 +26,32 @@ func installCommand(binaryName string, messages ...string) error {
// If the cached file does not exist, download the binary
url, err := findURL(binaryName)
if err != nil {
return fmt.Errorf("Error: %v", err)
errorOut("%v\n", err)
}
if err := fetchBinaryFromURL(url, installPath); err != nil {
return fmt.Errorf("Error: Could not install binary: %v", err)
}

// Check if any messages are provided and print them
if len(messages) > 0 && messages[0] != "" {
for _, message := range messages {
fmt.Printf(message)
// Check if the user provided a custom installMessage and If so, print it as per his requirements.
if len(installMessage) != 0 {
if installMessage[0] == "--fancy" {
if installMessage[1] == "--truncate" {
truncatePrintf(installMessage[2], binaryName)
} else {
fmt.Printf(installMessage[1], binaryName)
}
if len(installMessage) > 2 && installMessage[2] == "--newline" || len(installMessage) > 3 && installMessage[3] == "--newline" {
fmt.Println()
}
} else {
if installMessage[0] == "--truncate" {
fmt.Println(truncateSprintf("%s", installMessage[1]))
} else {
fmt.Println(installMessage[0])
}
}
} else {
// If no message provided, print default installation complete message
fmt.Printf("\x1b[A\033[KInstallation complete: %s \n", installPath)
fmt.Printf("Installation complete: %s\n", installPath)
}
return nil
}
5 changes: 2 additions & 3 deletions listBinaries.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// listBinaries.go // This file implements the listBinaries function //>

package main

import (
Expand Down Expand Up @@ -37,8 +36,8 @@ func listBinaries() ([]string, error) {

// Unmarshal JSON
var metadata []struct {
Name string `json:"name"`
NameAlt string `json:"Name"` // Consider both "name" and "Name" fields
Name string `json:"Name"` // Consider both "name" and "Name" fields
NameAlt string `json:"name"`
}
if err := json.Unmarshal(body, &metadata); err != nil {
return nil, fmt.Errorf("failed to unmarshal metadata JSON from %s: %v", url, err)
Expand Down
Loading

0 comments on commit ac681d1

Please sign in to comment.