Skip to content

Commit 3a59a64

Browse files
committed
Display version when called with --version
Fixes #64.
1 parent 0216164 commit 3a59a64

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313
)
1414

1515
var (
16+
Version = ""
17+
CommitSHA = ""
18+
1619
term = termenv.ColorProfile()
1720
theme Theme
1821

@@ -33,6 +36,7 @@ var (
3336

3437
inodes = flag.Bool("inodes", false, "list inode information instead of block usage")
3538
jsonOutput = flag.Bool("json", false, "output all devices in JSON format")
39+
version = flag.Bool("version", false, "display version")
3640
)
3741

3842
// renderTables renders all tables.
@@ -160,6 +164,18 @@ func parseHideFs(hideFs string) map[string]struct{} {
160164
func main() {
161165
flag.Parse()
162166

167+
if *version {
168+
if len(CommitSHA) > 7 {
169+
CommitSHA = CommitSHA[:7]
170+
}
171+
if Version == "" {
172+
Version = "unknown"
173+
CommitSHA = "built from source"
174+
}
175+
fmt.Printf("duf %s (%s)\n", Version, CommitSHA)
176+
os.Exit(0)
177+
}
178+
163179
// validate flags
164180
var err error
165181
theme, err = loadTheme(*themeOpt)

0 commit comments

Comments
 (0)