-
TzlilSwimmer123 authored
Co-authored-by:
Tzlil Swimmer <tzlilswimmer@Tzlils-MacBook-Pro.local> Co-authored-by:
Dima Brusilovsky <dimabru@gmail.com>
Unverified5095edd7
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
package main
import (
"errors"
"fmt"
"os"
"github.com/datreeio/datree/pkg/networkValidator"
"github.com/datreeio/datree/pkg/cliClient"
"github.com/datreeio/datree/pkg/deploymentConfig"
"github.com/datreeio/datree/pkg/localConfig"
"github.com/datreeio/datree/pkg/printer"
"github.com/datreeio/datree/pkg/utils"
"github.com/datreeio/datree/bl/errorReporter"
"github.com/datreeio/datree/cmd"
"github.com/datreeio/datree/cmd/test"
)
const DEFAULT_ERR_EXIT_CODE = 1
const VIOLATIONS_FOUND_EXIT_CODE = 2
func main() {
validator := networkValidator.NewNetworkValidator()
cliClient := cliClient.NewCliClient(deploymentConfig.URL, validator)
localConfig := localConfig.NewLocalConfigClient(cliClient, validator)
reporter := errorReporter.NewErrorReporter(cliClient, localConfig)
globalPrinter := printer.CreateNewPrinter()
defer func() {
if panicErr := recover(); panicErr != nil {
reporter.ReportPanicError(panicErr)
globalPrinter.PrintMessage(fmt.Sprintf("Unexpected error: %s\n", utils.ParseErrorToString(panicErr)), "error")
os.Exit(DEFAULT_ERR_EXIT_CODE)
}
}()
if err := cmd.Execute(); err != nil {
if errors.Is(err, test.ViolationsFoundError) {
os.Exit(VIOLATIONS_FOUND_EXIT_CODE)
}
reporter.ReportUnexpectedError(err)
os.Exit(DEFAULT_ERR_EXIT_CODE)
}
}