diff --git a/app/app_download.go b/app/app_download.go index 09e887d..a964835 100644 --- a/app/app_download.go +++ b/app/app_download.go @@ -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 } @@ -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") }), diff --git a/app/application.go b/app/application.go index 5cab43f..f319b94 100644 --- a/app/application.go +++ b/app/application.go @@ -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" @@ -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 { @@ -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)) } } @@ -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 } @@ -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 } @@ -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 } diff --git a/lib/appflags/flags.go b/lib/appflags/flags.go index 93b7207..875e074 100644 --- a/lib/appflags/flags.go +++ b/lib/appflags/flags.go @@ -18,6 +18,7 @@ type Flags struct { DisableSSL bool NoInteraction bool Verbose bool + NoProgress bool } type CliFlags struct { @@ -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"` } diff --git a/lib/data/types.go b/lib/data/types.go index e2bccae..a61bd75 100644 --- a/lib/data/types.go +++ b/lib/data/types.go @@ -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) { diff --git a/lib/home/compactor.go b/lib/home/compactor.go new file mode 100644 index 0000000..d637173 --- /dev/null +++ b/lib/home/compactor.go @@ -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 +}