Skip to content

Commit

Permalink
feat: add --show-mtime (-M) option
Browse files Browse the repository at this point in the history
fixes #242
  • Loading branch information
dundee committed Apr 23, 2024
1 parent f8802e6 commit e621676
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
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 @@ type Flags struct {
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 @@ func (a *App) createUI() (UI, error) {
ui.SetShowItemCount()
})
}
if a.Flags.ShowMTime {
opts = append(opts, func(ui *tui.UI) {
ui.SetShowMTime()
})
}
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

0 comments on commit e621676

Please sign in to comment.