Skip to content

Commit a32ab9d

Browse files
authored
Refactor: Remove unused progress bar functions (#418)
1 parent beabb42 commit a32ab9d

7 files changed

Lines changed: 10 additions & 26 deletions

File tree

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ qp [command] [args] [options]
294294

295295
- `--no-headers`: omit column headers in table output (useful for scripting)
296296
- `--full-timestamp`: display the full timestamp (date and time) of package update/build instead of just the date
297-
- `--no-progress`: force no progress bar outside of non-interactive environments
298297
- `--no-cache`: disable cache loading/saving and force fresh package data loading
299298
- `--regen-cache`: disable cache loading, force fresh package data loading, and save fresh cache
300299
- `--cache-only`: update cache only and nothing else. specify origin ('pacman', 'brew', 'deb', etc.) or all.
@@ -668,7 +667,7 @@ output format:
668667

669668
boolean flags can be explicitly set using `--<option>=true` or `--<option>=false`:
670669
```
671-
qp --no-headers=true --no-progress=true
670+
qp --no-headers=true
672671
```
673672

674673
arguments to queries can be quoted if they contain special characters or spaces:
@@ -681,9 +680,6 @@ output format:
681680
qp --no-headers select name,size | awk '{print $1, $2}'
682681
```
683682

684-
**note**: `--no-progress` is automatically set to `true` in non-interactive environments, so you can pipe into programs like `cat`, `grep`, or `less` without issue.
685-
686-
687683
### examples
688684

689685
1. show the last 10 installed packages

cmd/qp/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func mainWithConfig(configProvider config.ConfigProvider) error {
3939
return rebuildCache(cfg.CacheWorker)
4040
}
4141

42-
isInteractive := isInteractive(cfg.DisableProgress)
4342
cacheBaseDir, err := storage.GetCachePath()
4443
if err != nil {
4544
out.WriteLine(fmt.Sprintf("WARNING: failed to set up cache dir: %v", err))
@@ -91,7 +90,7 @@ func mainWithConfig(configProvider config.ConfigProvider) error {
9190
}
9291

9392
if len(allPkgs) == 0 {
94-
if isInteractive {
93+
if isInteractive() {
9594
out.WriteLine("No packages to display.")
9695
}
9796

@@ -112,6 +111,6 @@ func mainWithConfig(configProvider config.ConfigProvider) error {
112111
return nil
113112
}
114113

115-
func isInteractive(disableProgress bool) bool {
116-
return term.IsTerminal(int(os.Stdout.Fd())) && !disableProgress
114+
func isInteractive() bool {
115+
return term.IsTerminal(int(os.Stdout.Fd()))
117116
}

internal/config/flags.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import (
88
"github.com/spf13/pflag"
99
)
1010

11-
const internalCacheWorker = "internal-cache-worker"
11+
const (
12+
internalCacheWorker = "internal-cache-worker"
13+
noProgress = "no-progress"
14+
)
1215

1316
func ParseFlags(args []string) (Config, error) {
1417
var cfg Config
@@ -51,13 +54,14 @@ func registerCommonFlags(cfg *Config) {
5154
pflag.BoolVarP(&cfg.ShowHelp, "help", "h", false, "Show help")
5255
pflag.BoolVar(&cfg.ShowVersion, "version", false, "Show version")
5356
pflag.BoolVar(&cfg.ShowFullTimestamp, "full-timestamp", false, "Show full timestamp")
54-
pflag.BoolVar(&cfg.DisableProgress, "no-progress", false, "Disable progress bar")
57+
pflag.BoolVar(&cfg.DisableProgress, noProgress, false, "Disable progress bar")
5558
pflag.BoolVar(&cfg.NoCache, "no-cache", false, "Disable cache")
5659
pflag.BoolVar(&cfg.RegenCache, "regen-cache", false, "Force fresh cache")
5760
pflag.StringVar(&cfg.CacheOnly, "cache-only", "", "Update cache only for specifed origin.")
5861
pflag.StringVar(&cfg.CacheWorker, internalCacheWorker, "", "Internal flag for background cache operations - do not use directly")
5962

6063
_ = pflag.CommandLine.MarkHidden(internalCacheWorker)
64+
_ = pflag.CommandLine.MarkHidden(noProgress)
6165

6266
var legacyJSON bool
6367
pflag.BoolVar(&legacyJSON, "json", false, "")

internal/display/output_manager.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ func PrintProgress(phase string, progress int, description string) {
4848
manager.printProgress(phase, progress, description)
4949
}
5050

51-
func ClearProgress() {
52-
manager.clearProgress()
53-
}
54-
5551
func RenderTable(
5652
pkgPtrs []*pkgdata.PkgInfo,
5753
fields []consts.FieldType,
@@ -88,10 +84,6 @@ func (o *OutputManager) printProgress(phase string, progress int, description st
8884
o.lastMsgLength = len(msg)
8985
}
9086

91-
func (o *OutputManager) clearProgress() {
92-
o.clearPrevMsg(0)
93-
}
94-
9587
func (o *OutputManager) formatProgessMsg(phase string, progress int, description string) string {
9688
msg := fmt.Sprintf("[%s] %d%% - %s", phase, progress, description)
9789

internal/display/render_kv.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ type kvEntry struct {
1414
}
1515

1616
func (o *OutputManager) renderKeyValue(pkgs []*pkgdata.PkgInfo, fields []consts.FieldType) {
17-
o.clearProgress()
18-
1917
dateFormat := consts.DateTimeFormat
2018
ctx := tableContext{DateFormat: dateFormat}
2119

internal/display/render_table.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ func (o *OutputManager) renderTable(
5353
showFullTimestamp bool,
5454
hasNoHeaders bool,
5555
) {
56-
o.clearProgress()
57-
5856
dateFormat := consts.DateOnlyFormat
5957
if showFullTimestamp {
6058
dateFormat = consts.DateTimeFormat

qp.1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ Omit column headers (useful in scripts).
6868
.B \-\-full-timestamp
6969
Show full date+time for install/build timestamps.
7070
.TP
71-
.B \-\-no-progress
72-
Disable progress bar.
73-
.TP
7471
.B \-\-no-cache
7572
Skip using cache, force fresh data load.
7673
.TP

0 commit comments

Comments
 (0)