Main is implemented here so both 'pp' and 'panicparse' executables can be compiled. This is to work around the Perl Package manager 'pp' that is preinstalled on some OSes.
()
| 190 | // compiled. This is to work around the Perl Package manager 'pp' that is |
| 191 | // preinstalled on some OSes. |
| 192 | func Main() error { |
| 193 | aggressive := flag.Bool("aggressive", false, "Aggressive deduplication including non pointers") |
| 194 | parse := flag.Bool("parse", true, "Parses source files to deduct types; use -parse=false to work around bugs in source parser") |
| 195 | rebase := flag.Bool("rebase", true, "Guess GOROOT and GOPATH") |
| 196 | verboseFlag := flag.Bool("v", false, "Enables verbose logging output") |
| 197 | filterFlag := flag.String("f", "", "Regexp to filter out headers that match, ex: -f 'IO wait|syscall'") |
| 198 | matchFlag := flag.String("m", "", "Regexp to filter by only headers that match, ex: -m 'semacquire'") |
| 199 | // Console only. |
| 200 | fullPathArg := flag.Bool("full-path", false, "Print full sources path") |
| 201 | relPathArg := flag.Bool("rel-path", false, "Print sources path relative to GOROOT or GOPATH; implies -rebase") |
| 202 | noColor := flag.Bool("no-color", !isatty.IsTerminal(os.Stdout.Fd()) || os.Getenv("TERM") == "dumb", "Disable coloring") |
| 203 | forceColor := flag.Bool("force-color", false, "Forcibly enable coloring when with stdout is redirected") |
| 204 | // HTML only. |
| 205 | html := flag.String("html", "", "Output an HTML file") |
| 206 | |
| 207 | var out io.Writer = os.Stdout |
| 208 | p := &defaultPalette |
| 209 | |
| 210 | flag.CommandLine.Usage = func() { |
| 211 | out = os.Stderr |
| 212 | if *noColor && !*forceColor { |
| 213 | p = &Palette{} |
| 214 | } else { |
| 215 | out = colorable.NewColorableStderr() |
| 216 | } |
| 217 | fmt.Fprintf(out, "Usage of %s:\n", os.Args[0]) |
| 218 | flag.CommandLine.SetOutput(out) |
| 219 | flag.CommandLine.PrintDefaults() |
| 220 | fmt.Fprintf(out, "\nLegend:\n") |
| 221 | fmt.Fprintf(out, " Type Exported Private\n") |
| 222 | fmt.Fprintf(out, " main %smain.Foo()%s %smain.foo()%s\n", |
| 223 | p.funcColor(stack.LocationUnknown, true, false), p.EOLReset, |
| 224 | p.funcColor(stack.LocationUnknown, true, true), p.EOLReset) |
| 225 | fmt.Fprintf(out, " <unknown> %spkg.Foo()%s %spkg.foo()%s\n", |
| 226 | p.funcColor(stack.LocationUnknown, false, false), p.EOLReset, |
| 227 | p.funcColor(stack.LocationUnknown, false, true), p.EOLReset) |
| 228 | fmt.Fprintf(out, " go.mod %spkg.Foo()%s %spkg.foo()%s\n", |
| 229 | p.funcColor(stack.GoMod, false, false), p.EOLReset, |
| 230 | p.funcColor(stack.GoMod, false, true), p.EOLReset) |
| 231 | fmt.Fprintf(out, " $GOPATH/src %spkg.Foo()%s %spkg.foo()%s\n", |
| 232 | p.funcColor(stack.GOPATH, false, false), p.EOLReset, |
| 233 | p.funcColor(stack.GOPATH, false, true), p.EOLReset) |
| 234 | fmt.Fprintf(out, " $GOPATH/pkg/mod %spkg.Foo()%s %spkg.foo()%s\n", |
| 235 | p.funcColor(stack.GoPkg, false, false), p.EOLReset, |
| 236 | p.funcColor(stack.GoPkg, false, true), p.EOLReset) |
| 237 | fmt.Fprintf(out, " $GOROOT/src %spkg.Foo()%s %spkg.Foo()%s\n", |
| 238 | p.funcColor(stack.Stdlib, false, false), p.EOLReset, |
| 239 | p.funcColor(stack.Stdlib, false, true), p.EOLReset) |
| 240 | } |
| 241 | flag.Parse() |
| 242 | |
| 243 | log.SetFlags(log.Lmicroseconds) |
| 244 | if !*verboseFlag { |
| 245 | log.SetOutput(io.Discard) |
| 246 | } |
| 247 | |
| 248 | var err error |
| 249 | var filter *regexp.Regexp |
searching dependent graphs…