-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
118 lines (102 loc) · 2.97 KB
/
Copy pathmain.go
File metadata and controls
118 lines (102 loc) · 2.97 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"fmt"
"os"
"runtime/debug"
"strings"
"github.com/PatchMon/lintree/internal/scanner"
"github.com/PatchMon/lintree/internal/ui"
"github.com/PatchMon/lintree/internal/version"
)
func main() {
// Soft memory limit. Too low = GC thrashes CPU. Too high = unbounded growth.
debug.SetMemoryLimit(1024 * 1024 * 1024) // 1GB
fast := false
var excludes []string
var args []string
// Parse flags
cliArgs := os.Args[1:]
for i := 0; i < len(cliArgs); i++ {
arg := cliArgs[i]
switch {
case arg == "-fast" || arg == "--fast":
fast = true
case arg == "-x" || arg == "-exclude" || arg == "--exclude":
if i+1 >= len(cliArgs) {
fmt.Fprintf(os.Stderr, "Error: %s requires a value\n", arg)
os.Exit(1)
}
i++
excludes = append(excludes, cliArgs[i])
case strings.HasPrefix(arg, "--exclude="):
excludes = append(excludes, strings.TrimPrefix(arg, "--exclude="))
case strings.HasPrefix(arg, "-exclude="):
excludes = append(excludes, strings.TrimPrefix(arg, "-exclude="))
case strings.HasPrefix(arg, "-x="):
excludes = append(excludes, strings.TrimPrefix(arg, "-x="))
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)
}
exclude, err := scanner.NewExclude(excludes)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: invalid --exclude: %s\n", err)
os.Exit(1)
}
if err := ui.Run(root, fast, exclude); 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
Flags:
--exclude, -x PATH Skip a path or name; repeatable, supports globs
e.g. lintree / --exclude /mnt --exclude /tmp
lintree ~/code -x node_modules -x '*.cache'
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
`)
}