Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --show-mtime (-M) option #350

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Flags:
-a, --show-apparent-size Show apparent size
-d, --show-disks Show all mounted disks
-C, --show-item-count Show number of items in directory
-M, --show-mtime Show latest mtime of items in directory
-B, --show-relative-size Show relative size
--si Show sizes with decimal SI prefixes (kB, MB, GB) instead of binary prefixes (KiB, MiB, GiB)
--storage-path string Path to persistent key-value storage directory (default is /tmp/badger) (default "/tmp/badger")
Expand Down
6 changes: 6 additions & 0 deletions cmd/gdu/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
ShowRelativeSize bool `yaml:"show-relative-size"`
ShowVersion bool `yaml:"-"`
ShowItemCount bool `yaml:"show-item-count"`
ShowMTime bool `yaml:"show-mtime"`
NoColor bool `yaml:"no-color"`
NoMouse bool `yaml:"no-mouse"`
NonInteractive bool `yaml:"non-interactive"`
Expand Down Expand Up @@ -277,6 +278,11 @@
ui.SetShowItemCount()
})
}
if a.Flags.ShowMTime {
opts = append(opts, func(ui *tui.UI) {
ui.SetShowMTime()
})

Check warning on line 284 in cmd/gdu/app/app.go

View check run for this annotation

Codecov / codecov/patch

cmd/gdu/app/app.go#L282-L284

Added lines #L282 - L284 were not covered by tests
}
if a.Flags.NoDelete {
opts = append(opts, func(ui *tui.UI) {
ui.SetNoDelete()
Expand Down
1 change: 1 addition & 0 deletions cmd/gdu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func init() {
flags.BoolVarP(&af.ShowRelativeSize, "show-relative-size", "B", false, "Show relative size")
flags.BoolVarP(&af.NoColor, "no-color", "c", false, "Do not use colorized output")
flags.BoolVarP(&af.ShowItemCount, "show-item-count", "C", false, "Show number of items in directory")
flags.BoolVarP(&af.ShowMTime, "show-mtime", "M", false, "Show latest mtime of items in directory")
flags.BoolVarP(&af.NonInteractive, "non-interactive", "n", false, "Do not run in interactive mode")
flags.BoolVarP(&af.NoProgress, "no-progress", "p", false, "Do not show progress in non-interactive mode")
flags.BoolVarP(&af.Summarize, "summarize", "s", false, "Show only a total in non-interactive mode")
Expand Down
2 changes: 2 additions & 0 deletions gdu.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ non-interactive mode

**-C**, **\--show-item-count**\[=false\] Show number of items in directory

**-M**, **\--show-mtime**\[=false\] Show latest mtime of items in directory

**\--si**\[=false\] Show sizes with decimal SI prefixes (kB, MB, GB) instead of binary prefixes (KiB, MiB, GiB)

**\--no-prefix**\[=false\] Show sizes as raw numbers without any prefixes (SI or binary) in non-interactive mode
Expand Down
5 changes: 5 additions & 0 deletions tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ func (ui *UI) SetShowItemCount() {
ui.showItemCount = true
}

// SetShowMTime sets the flag to show last modification time of items in directory
func (ui *UI) SetShowMTime() {
ui.showMtime = true
}

// SetNoDelete disables all write operations
func (ui *UI) SetNoDelete() {
ui.noDelete = true
Expand Down
12 changes: 12 additions & 0 deletions tui/tui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,18 @@ func TestSetShowItemCount(t *testing.T) {
assert.Equal(t, ui.showItemCount, true)
}

func TestSetShowMTime(t *testing.T) {
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()

app := testapp.CreateMockedApp(true)
ui := CreateUI(app, simScreen, &bytes.Buffer{}, false, true, false, false, false)

ui.SetShowMTime()

assert.Equal(t, ui.showMtime, true)
}

func TestNoDelete(t *testing.T) {
simScreen := testapp.CreateSimScreen()
defer simScreen.Fini()
Expand Down
Loading