Skip to content

Commit

Permalink
improve output formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
crhuber committed Feb 15, 2024
1 parent edb9865 commit a8d24ef
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/urfave/cli/v2"
)

var version = "1.12.5"
var version = "1.12.6"

func main() {

Expand Down Expand Up @@ -146,12 +146,12 @@ func main() {
return fmt.Errorf("%s", err)
}

fmt.Printf("\n[%s/%s]", p.Owner, p.Repo)
fmt.Printf("\nRelease: %s", p.Release)
fmt.Printf("\nDescription: %s", p.Description)
fmt.Printf("\nUrl: https://github.com/%s/%s", p.Owner, p.Repo)
fmt.Printf("\nBinary: %s", p.Binary)
fmt.Printf("\nUpdated At: %s", p.UpdatedAt)
fmt.Printf("[%s/%s]\n", p.Owner, p.Repo)
fmt.Printf("Release: %s\n", p.Release)
fmt.Printf("Description: %s\n", p.Description)
fmt.Printf("Url: https://github.com/%s/%s\n", p.Owner, p.Repo)
fmt.Printf("Binary: %s\n", p.Binary)
fmt.Printf("Updated At: %s\n", p.UpdatedAt)
return nil
},
},
Expand Down
24 changes: 12 additions & 12 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ func (kc *KelpConfig) Save() error {
if err != nil {
return err
}
fmt.Println("\nConfig saved.")
fmt.Println("Config saved.")
return nil
}

func (kc *KelpConfig) RemovePackage(repo string) error {
for i, kp := range kc.Packages {
if kp.Repo == repo {
kc.Packages = kc.Pop(i)
fmt.Printf("\nPackage %s removed", repo)
fmt.Printf("Package %s removed\n", repo)
return nil
}
}
Expand All @@ -120,7 +120,7 @@ func (kc *KelpConfig) AddPackage(owner, repo, release string) error {
UpdatedAt: time.Now(),
}
kc.Packages = append(kc.Packages, kp)
fmt.Println("\nConfig added!")
fmt.Println("Config added!")

return nil
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func (kc *KelpConfig) SetPackage(repo, release, description, binary string) erro
if binary != "" {
kc.Packages[i].Binary = binary
}
fmt.Println("\nConfig set!")
fmt.Println("Config set!")
return nil
}
}
Expand Down Expand Up @@ -243,23 +243,23 @@ func (kc *KelpConfig) List() {

func Initialize(path string) error {
if !utils.DirExists(KelpDir) {
fmt.Println("\nCreating Kelp dir...")
fmt.Println("Creating Kelp dir...")
err := os.Mkdir(KelpDir, 0777)
if err != nil {
return err
}
}

if !utils.DirExists(KelpCache) {
fmt.Println("\nCreating Kelp cache...")
fmt.Println("Creating Kelp cache...")
err := os.Mkdir(KelpCache, 0777)
if err != nil {
return err
}
}

if !utils.DirExists(KelpBin) {
fmt.Println("\nCreating Kelp bin...")
fmt.Println("Creating Kelp bin...")
err := os.Mkdir(KelpBin, 0777)
if err != nil {
return err
Expand All @@ -279,17 +279,17 @@ func Initialize(path string) error {
kc.Packages = append(kc.Packages, kp)

if !utils.FileExists(path) {
fmt.Println("\nCreating Kelp config file...")
fmt.Println("Creating Kelp config file...")
err := kc.Save()
if err != nil {
return err
}
} else {
fmt.Println("\nSkipping Kelp config file creation since one alredy exists...")
fmt.Println("Skipping Kelp config file creation since one alredy exists...")
}

fmt.Println("\n🌱 Kelp Initialized!")
fmt.Printf("\n🗒 Add Kelp to your path by running: \nexport PATH=%s:$PATH >> ~/.bash_profile", KelpBin)
fmt.Println("🌱 Kelp Initialized!")
fmt.Printf("🗒 Add Kelp to your path by running: \nexport PATH=%s:$PATH >> ~/.bash_profile\n", KelpBin)
return nil
}

Expand All @@ -309,7 +309,7 @@ func Inspect() {
func Browse(owner, repo string) {
var err error
url := fmt.Sprintf("https://github.com/%s/%s", owner, repo)
fmt.Printf("\nOpening %s", url)
fmt.Printf("Opening %s\n", url)

switch runtime.GOOS {
case "darwin":
Expand Down
28 changes: 14 additions & 14 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func Install(owner, repo, release string) error {

// downloadFile downloads files
func downloadFile(filepath string, url string) error {
fmt.Printf("\n===> Downloading %s ...", url)
fmt.Printf("\nTo: %s ...", filepath)
fmt.Printf("===> Downloading %s...\n", url)
fmt.Printf("To: %s...\n", filepath)

// Get the data
req, _ := http.NewRequest("GET", url, nil)
Expand Down Expand Up @@ -108,7 +108,7 @@ func downloadFile(filepath string, url string) error {
}

func extractPackage(downloadPath, tempDir string) error {
fmt.Printf("\n📂 Extracting %s", downloadPath)
fmt.Printf("📂 Extracting %s\n", downloadPath)
reader, err := os.Open(downloadPath)
if err != nil {
return errors.New("could read archive")
Expand Down Expand Up @@ -159,22 +159,22 @@ func extractPackage(downloadPath, tempDir string) error {
return nil
}
if strings.HasSuffix(downloadPath, ".dmg") {
fmt.Println("\nSkippping dmg..")
fmt.Println("Skippping dmg..")
return errors.New("kelp does not support dmg files")
}
// sometimes there is no unzip file and its just the file
fp := strings.SplitAfter(downloadPath, "/")
fn := fp[len(fp)-1]
if !strings.Contains(fn, ".") {
fmt.Println("\nFound unextractable file. Installing instead")
fmt.Println("Found unextractable file. Installing instead")
installBinary(downloadPath)
return nil
}
return errors.New("archive file format not known")
}

func installBinary(tempDir string) {
fmt.Println("\n🧐 Checking for binary files in extract...")
fmt.Println("🧐 Checking for binary files in extract...")
files, err := utils.FilePathWalkDir(tempDir)
if err != nil {
log.Panic("Could not walk directory")
Expand All @@ -185,11 +185,11 @@ func installBinary(tempDir string) {
if mime.String() == "application/x-mach-binary" {
splits := strings.SplitAfter(file, "/")
fileName := splits[len(splits)-1]
fmt.Printf("\nBinary file %s found in extract.", fileName)
fmt.Printf("Binary file %s found in extract.\n", fileName)
destination := filepath.Join(config.KelpBin, fileName)
fmt.Printf("\n💾 Copying %v to kelp bin...", fileName)
fmt.Printf("💾 Copying %v to kelp bin...\n", fileName)
utils.CopyFile(file, destination)
fmt.Printf("\n✅ Installed %v !", fileName)
fmt.Printf("✅ Installed %v !\n", fileName)
}
}
}
Expand Down Expand Up @@ -227,13 +227,13 @@ func evaluateAssetSuitability(asset types.Asset) int {

func findGithubReleaseMacAssets(assets []types.Asset) (types.Asset, error) {

fmt.Println("\n🍏 Finding mac assets to download...")
fmt.Println("🍏 Finding mac assets to download...")
assetScores := map[int]int{}
for index, asset := range assets {
filename := strings.Split(asset.BrowserDownloadURL, "/")
assetScore := evaluateAssetSuitability(asset)
if assetScore >= 6 {
fmt.Printf("\nFound suitable candiate %v for download. Score: %v", filename[len(filename)-1], assetScore)
fmt.Printf("Found suitable candiate %v for download. Score: %v\n", filename[len(filename)-1], assetScore)
assetScores[index] = assetScore
}

Expand All @@ -246,12 +246,12 @@ func findGithubReleaseMacAssets(assets []types.Asset) (types.Asset, error) {
highest := getHighestScore(assetScores)
bestAsset := assets[highest.Key]
filename := strings.Split(bestAsset.BrowserDownloadURL, "/")
fmt.Printf("\nAdding highest ranked asset %v to download queue.", filename[len(filename)-1])
fmt.Printf("Adding highest ranked asset %v to download queue.\n", filename[len(filename)-1])
return bestAsset, nil
}

func downloadGithubRelease(owner, repo, release string) (types.Asset, error) {
fmt.Printf("\n===> Installing %s/%s:%s ...", owner, repo, release)
fmt.Printf("===> Installing %s/%s:%s...\n", owner, repo, release)
ghr, err := utils.GetGithubRelease(owner, repo, release)
if err != nil {
return types.Asset{}, err
Expand All @@ -263,7 +263,7 @@ func downloadGithubRelease(owner, repo, release string) (types.Asset, error) {

downloadPath := filepath.Join(config.KelpCache, downloadableAsset.Name)
if utils.FileExists(downloadPath) {
fmt.Printf("\nFile %v already exists in cache, skipping download.", downloadableAsset.Name)
fmt.Printf("File %v already exists in cache, skipping download.\n", downloadableAsset.Name)
} else {
err := downloadFile(downloadPath, downloadableAsset.BrowserDownloadURL)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/rm/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func RemoveBinary(binary string) error {
binaryPath := filepath.Join(config.KelpBin, binary)
if utils.FileExists(binaryPath) {
fmt.Printf("\nRemoving binary %s...", binary)
fmt.Printf("Removing binary %s...\n", binary)
err := os.Remove(binaryPath)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@ func CommandExists(cmd string) (string, error) {
func GetGithubRelease(owner, repo, release string) (types.GithubRelease, error) {
var url string
if release == "latest" {
fmt.Printf("\n🌐 Getting releases for %s/%s:%s ...", owner, repo, release)
fmt.Printf("🌐 Getting releases for %s/%s:%s...\n", owner, repo, release)
url = fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/%s", owner, repo, release)

} else {
// try by tag
fmt.Printf("\n🌐 Getting releases by tag %s ...", release)
fmt.Printf("🌐 Getting releases by tag %s...\n", release)
url = fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/tags/%s", owner, repo, release)
}

Expand All @@ -284,7 +284,7 @@ func GetGithubRelease(owner, repo, release string) (types.GithubRelease, error)
// set headers for github auth
ghToken := os.Getenv("GITHUB_TOKEN")
if ghToken != "" {
fmt.Println("\nUsing Github token in http request")
fmt.Println("Using Github token in http request")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", ghToken))
}

Expand Down

0 comments on commit a8d24ef

Please sign in to comment.