summaryrefslogtreecommitdiffstats
path: root/stdout
diff options
context:
space:
mode:
authorRiatre Foo <foo@riat.re>2022-06-09 16:38:49 +0800
committerDaniel Milde <daniel@milde.cz>2022-06-09 18:20:41 +0200
commit1a7dea1dd853c61a7f79cccde4b2de8a17df8b8a (patch)
tree6b764c74449e11f6da8b7ba6a0da81f0ab43f941 /stdout
parente34d96152c24d31ad536d8bf309a313fb53c0fc8 (diff)
fix: honor --summarize when reading analysis
Before this change, gdu produces different output for `gdu -nps` and `gdu -p -o- | gdu -nps -f-`. Check ui.summarize in ReadAnalysis, similar to AnalyzePath.
Diffstat (limited to 'stdout')
-rw-r--r--stdout/stdout.go6
-rw-r--r--stdout/stdout_test.go13
2 files changed, 18 insertions, 1 deletions
diff --git a/stdout/stdout.go b/stdout/stdout.go
index e98fc10..e675abd 100644
--- a/stdout/stdout.go
+++ b/stdout/stdout.go
@@ -265,7 +265,11 @@ func (ui *UI) ReadAnalysis(input io.Reader) error {
return err
}
- ui.showDir(dir)
+ if ui.summarize {
+ ui.printTotalItem(dir)
+ } else {
+ ui.showDir(dir)
+ }
return nil
}
diff --git a/stdout/stdout_test.go b/stdout/stdout_test.go
index 5a95dc4..425765b 100644
--- a/stdout/stdout_test.go
+++ b/stdout/stdout_test.go
@@ -186,6 +186,19 @@ func TestReadAnalysisWithWrongFile(t *testing.T) {
assert.NotNil(t, err)
}
+func TestReadAnalysisWithSummarize(t *testing.T) {
+ input, err := os.OpenFile("../internal/testdata/test.json", os.O_RDONLY, 0644)
+ assert.Nil(t, err)
+
+ output := bytes.NewBuffer(make([]byte, 10))
+
+ ui := CreateStdoutUI(output, false, false, false, false, true, false, false)
+ err = ui.ReadAnalysis(input)
+
+ assert.Nil(t, err)
+ assert.Contains(t, output.String(), " gdu\n")
+}
+
func TestMaxInt(t *testing.T) {
assert.Equal(t, 5, maxInt(2, 5))
assert.Equal(t, 4, maxInt(4, 2))