-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
87 lines (75 loc) · 1.89 KB
/
Copy pathmain.go
File metadata and controls
87 lines (75 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"lintree/internal/ui"
"lintree/internal/version"
"os"
"runtime/debug"
)
func main() {
// Soft memory limit. Too low = GC thrashes CPU. Too high = unbounded growth.
debug.SetMemoryLimit(1024 * 1024 * 1024) // 1GB
fast := false
var args []string
// Parse flags
for _, arg := range os.Args[1:] {
switch arg {
case "-fast", "--fast":
fast = true
default:
args = append(args, arg)
}
}
if len(args) > 0 {
switch args[0] {
case "-v", "--version", "version":
fmt.Print(version.Full())
if latest, available, err := version.CheckForUpdate(); err == nil {
if available {
fmt.Printf("\n Update available: %s -> %s\n", version.Version, latest)
fmt.Printf(" Run: %s\n", version.UpdateCommand())
} else {
fmt.Println("\n You're on the latest version.")
}
}
return
case "-h", "--help", "help":
printUsage()
return
}
}
root := "."
if len(args) > 0 {
root = args[0]
}
info, err := os.Stat(root) //nolint:gosec // user-provided path is intentional
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
if !info.IsDir() {
fmt.Fprintf(os.Stderr, "Error: %s is not a directory\n", root)
os.Exit(1)
}
if err := ui.Run(root, fast); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
}
func printUsage() {
fmt.Print(`lintree - Terminal disk usage visualizer
Usage:
lintree [path] Scan and visualize disk usage (default: current directory)
lintree -fast [path] Fast scan mode (more workers, higher CPU usage)
lintree -v Show version and check for updates
lintree -h Show this help
Controls:
arrows / jk Navigate cells
arrows / hl Spatial movement
Enter / l Drill into directory
Backspace / h Go back
? Help overlay
q / Ctrl+C Quit
Website: https://lintree.sh
`)
}