github.com/josephvusich/fdf@v0.0.0-20230522095411-9326dd32e33f/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/signal"
     7  	"syscall"
     8  )
     9  
    10  func main() {
    11  	// TODO check console width to truncate and avoid autoscroll when non-quiet
    12  	// TODO auto quiet on error, as it means probably not a terminal
    13  	if prevANSI, err := terminalANSI(true); err == nil && !prevANSI {
    14  		defer terminalANSI(prevANSI)
    15  	}
    16  
    17  	scanner := newScanner()
    18  	dirs := scanner.options.ParseArgs(os.Args)
    19  
    20  	sigs := make(chan os.Signal, 1)
    21  	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
    22  	go func() {
    23  		sig := <-sigs
    24  		fmt.Println("\nReceived", sig)
    25  		fmt.Printf("\n%s\n", scanner.totals.PrettyFormat(scanner.options.Verb()))
    26  		scanner.Exit(1)
    27  	}()
    28  
    29  	scanErr := scanner.Scan(dirs...)
    30  
    31  	fmt.Printf("\033[2K\n%s\n", scanner.totals.PrettyFormat(scanner.options.Verb()))
    32  
    33  	if err := writeReport(scanner.options.JsonReport, scanner.table.pairs, scanner.table.namePairs); err != nil {
    34  		fmt.Println("Unable to write JSON report:", err)
    35  	}
    36  
    37  	if scanErr != nil {
    38  		fmt.Printf("Finished with error: %s\n", scanErr)
    39  		os.Exit(1)
    40  	}
    41  }