aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: b939b212c1807e93840150e04b0c7cb140879906 (plain) (blame)
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
package main

import (
	"fmt"
	tea "github.com/charmbracelet/bubbletea"
	"os"
	"path/filepath"
)

func main() {
	rootPath, pathError := resolveRootPath()

	if pathError != nil {
		fmt.Fprintf(os.Stderr, "error: %s\n", pathError)
		os.Exit(1)
	}

	finalModel, runError := tea.NewProgram(
		initialModel(rootPath),
		tea.WithAltScreen(),
	).Run()

	if runError != nil {
		fmt.Fprintf(os.Stderr, "error: %s\n", runError)
		os.Exit(1)
	}

	if model, isApplicationModel := finalModel.(applicationModel); isApplicationModel {
		if model.scanError != nil {
			fmt.Fprintf(os.Stderr, "error: %s\n", model.scanError)
			os.Exit(1)
		}

		if model.deletedCount > 0 {
			fmt.Printf("deleted %d directories, freed %s\n", model.deletedCount, formatBytes(model.freedBytes))
		}
	}
}

func resolveRootPath() (string, error) {
	if len(os.Args) > 1 {
		return filepath.Abs(os.Args[1])
	}

	return os.Getwd()
}