Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
patinthehat committed May 14, 2024
1 parent e0f08b5 commit ffe534b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
7 changes: 4 additions & 3 deletions app/app_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func getGithubToken() (string, error) {
}

func (app *Application) getDownloadProgressBar(size int64) *pb.ProgressBar {
var pbout io.Writer = app.Outputs.Stderr
if app.Opts.Quiet {
var pbout io.Writer = app.Output

if app.Opts.Quiet || app.Opts.NoProgress {
pbout = io.Discard
}

Expand All @@ -53,7 +54,7 @@ func (app *Application) getDownloadProgressBar(size int64) *pb.ProgressBar {
pb.OptionShowCount(),
pb.OptionSpinnerType(14),
pb.OptionFullWidth(),
pb.OptionSetDescription("Downloading"),
pb.OptionSetDescription("› progress"),
pb.OptionOnCompletion(func() {
fmt.Fprint(pbout, "\n")
}),
Expand Down
10 changes: 5 additions & 5 deletions app/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/permafrost-dev/eget/lib/finders"
"github.com/permafrost-dev/eget/lib/github"
. "github.com/permafrost-dev/eget/lib/globals"
"github.com/permafrost-dev/eget/lib/home"
"github.com/permafrost-dev/eget/lib/reporters"
"github.com/permafrost-dev/eget/lib/utilities"
. "github.com/permafrost-dev/eget/lib/utilities"
Expand Down Expand Up @@ -152,7 +153,7 @@ func (app *Application) Run() *ReturnStatus {

assetWrapper.Asset = &asset

app.WriteLine(assetWrapper.Asset.DownloadURL) // print the URL
app.WriteLine("› downloading %s...", assetWrapper.Asset.DownloadURL) // print the URL

body, err := app.downloadAsset(assetWrapper.Asset, &findResult) // download with progress bar and get the response body
if err != nil {
Expand Down Expand Up @@ -408,7 +409,7 @@ func (app *Application) ProcessFlags(errorHandler ProcessFlagsErrorHandlerFunc)
if err := os.Remove(fn); err != nil {
app.WriteErrorLine("%s", err.Error())
} else {
app.WriteLine("Removed `%s`", fn)
app.WriteLine("Removed `%s`", home.NewPathCompactor().Compact(fn))
}
}

Expand All @@ -419,6 +420,7 @@ func (app *Application) ProcessFlags(errorHandler ProcessFlagsErrorHandlerFunc)
}

app.Opts.Verbose = app.cli.Verbose != nil && *app.cli.Verbose
app.Opts.NoProgress = app.cli.NoProgress != nil && *app.cli.NoProgress

return target, nil
}
Expand All @@ -428,14 +430,12 @@ func (app *Application) downloadAsset(asset *Asset, findResult *finders.FindResu

repo, _ := app.Cache.AddRepository(asset.Name, "", []string{}, findResult, time.Now().Add(time.Hour*1))
repo.UpdateCheckedAt()
app.Cache.SaveToFile()

if err := app.Download(asset.DownloadURL, buf); err != nil {
return []byte{}, fmt.Errorf("%s (URL: %s)", err, asset.DownloadURL)
}

repo.UpdateDownloadedAt(asset.DownloadURL)
app.Cache.SaveToFile()

return buf.Bytes(), nil
}
Expand Down Expand Up @@ -525,7 +525,7 @@ func (app *Application) extract(bin ExtractedFile) error {
return err
}

app.WriteLine("Extracted `%s` to `%s`", bin.ArchiveName, out)
app.WriteLine("› extracted `%s` to `%s`", bin.ArchiveName, home.NewPathCompactor().Compact(out))

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions lib/appflags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Flags struct {
DisableSSL bool
NoInteraction bool
Verbose bool
NoProgress bool
}

type CliFlags struct {
Expand All @@ -41,4 +42,5 @@ type CliFlags struct {
DisableSSL *bool `short:"k" long:"disable-ssl" description:"disable SSL verification for download requests"`
NoInteraction bool `long:"no-interaction" description:"do not prompt for user input"`
Verbose *bool `short:"v" long:"verbose" description:"show verbose output"`
NoProgress *bool `long:"no-progress" description:"do not show download progress"`
}
6 changes: 3 additions & 3 deletions lib/data/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func (ad *ApplicationData) SetRepositoryEntryByKey(key string, entry *Repository
func (rce *RepositoryCacheEntry) UpdateCheckedAt() {
rce.LastCheckAt = time.Now()

// if rce.owner != nil {
// rce.owner.SaveToFile()
// }
if rce.owner != nil {
rce.owner.SaveToFile()
}
}

func (rce *RepositoryCacheEntry) UpdateDownloadedAt(tag string) {
Expand Down
22 changes: 22 additions & 0 deletions lib/home/compactor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package home

import "strings"

type PathCompactor struct {
HomePath string
}

func NewPathCompactor() *PathCompactor {
path, _ := NewPathExpander().HomeDirectory()

return &PathCompactor{
HomePath: path,
}
}

func (pc *PathCompactor) Compact(path string) string {
if strings.HasPrefix(path, pc.HomePath) {
path = strings.Replace(path, pc.HomePath, "~", 1)
}
return path
}

0 comments on commit ffe534b

Please sign in to comment.