Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
70 lines (62 loc) · 1.62 KB
/
Copy pathmain.go
File metadata and controls
70 lines (62 loc) · 1.62 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
package main
import (
"flag"
"fmt"
"os"
"runtime"
"strings"
"astral-drive/internal/env"
"astral-drive/internal/processor"
"astral-drive/internal/scanner"
"astral-drive/internal/ui"
)
func main() {
topN := flag.Int("n", 20, "表示件数")
workers := flag.Int("w", runtime.NumCPU()*2, "Worker 数")
noColor := flag.Bool("no-color", false, "カラー出力を無効化")
exclude := flag.String("exclude", "", "除外するディレクトリ名(カンマ区切り)例: node_modules,.git")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: astral-drive [flags] [path]\n\nFlags:\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nExample:\n astral-drive\n astral-drive -n 10 /home\n astral-drive -exclude node_modules,.git C:\\\n")
}
flag.Parse()
// スキャン対象パスの決定
var roots []string
if flag.NArg() > 0 {
root := flag.Arg(0)
if _, err := os.Stat(root); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
roots = []string{root}
} else {
roots = env.Detect()
}
// 除外リストを解析
var excludeList []string
if *exclude != "" {
for _, e := range strings.Split(*exclude, ",") {
if t := strings.TrimSpace(e); t != "" {
excludeList = append(excludeList, t)
}
}
}
// スキャン実行
cfg := scanner.Config{
Workers: *workers,
Exclude: excludeList,
}
result, err := scanner.Run(roots, cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
// 上位 N 件を抽出
entries := processor.TopN(result.Sizes, *topN)
// 表示
uiCfg := ui.Config{
NoColor: *noColor,
}
ui.Render(entries, result, uiCfg)
}