-
Notifications
You must be signed in to change notification settings - Fork 39
/
main.go
86 lines (67 loc) · 1.43 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/byterocket/c4udit/analyzer"
)
func main() {
flag.Parse()
if *help {
printHelpAndExit()
}
// Expect at least one user argument.
if len(flag.Args()) == 0 {
printHelpAndExit()
}
// Run analyzer.
report, err := analyzer.Run(
analyzer.AllIssues(),
flag.Args(),
)
if err != nil {
printErrorAndExit(err)
}
if *saveToFile {
// Save report in markdown format to file.
err = ioutil.WriteFile(
"c4udit-report.md",
[]byte(report.Markdown()),
0777,
)
if err != nil {
printErrorAndExit(err)
}
} else {
// Print report to stdout.
fmt.Println(report.String())
}
}
// Flags
var (
help = flag.Bool("h", false, "Print help text.")
saveToFile = flag.Bool("s", false, "Save report as file.")
)
const helpText = `c4udit is a static analyzer for solidity contracts based on regexs.
It is capable of finding low risk issues and gas optimizations documented in
the c4-common-issues[1] repository.
Note that c4udit has a high rate of false positives. Check the results carefully!
Usage:
c4udit [flags] [files...]
Flags:
-h Print help text.
-s Save report as file.
References:
[1] https://github.com/byterocket/c4-common-issues
Provided with ❤ by ByteRocket
`
func printHelpAndExit() {
fmt.Print(helpText)
os.Exit(0)
}
func printErrorAndExit(err error) {
fmt.Println("c4checker Error:")
fmt.Print(err.Error())
os.Exit(1)
}