-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (33 loc) · 1.01 KB
/
main.go
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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
// TODO check console width to truncate and avoid autoscroll when non-quiet
// TODO auto quiet on error, as it means probably not a terminal
if prevANSI, err := terminalANSI(true); err == nil && !prevANSI {
defer terminalANSI(prevANSI)
}
scanner := newScanner()
dirs := scanner.options.ParseArgs(os.Args)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
fmt.Println("\nReceived", sig)
fmt.Printf("\n%s\n", scanner.totals.PrettyFormat(scanner.options.Verb()))
scanner.Exit(1)
}()
scanErr := scanner.Scan(dirs...)
fmt.Printf("\033[2K\n%s\n", scanner.totals.PrettyFormat(scanner.options.Verb()))
if err := writeReport(scanner.options.JsonReport, scanner.table.pairs, scanner.table.namePairs, scanner.table.db); err != nil {
fmt.Println("Unable to write JSON report:", err)
}
if scanErr != nil {
fmt.Printf("Finished with error: %s\n", scanErr)
os.Exit(1)
}
}