func main()

in tools/go-agent/cmd/main.go [34:93]


func main() {
	args := os.Args[1:]
	var err error
	var firstNonOptionIndex int
	// Print usage
	if firstNonOptionIndex, err = tools.ParseFlags(toolFlags, args); err != nil || toolFlags.Help {
		PrintUsageWithExit()
	}
	if toolFlags.Inject != "" {
		if err1 := InjectProject(toolFlags); err1 != nil {
			log.Fatal(err1)
		}
		return
	} else if toolFlags.Version {
		PrintVersion()
		return
	} else if firstNonOptionIndex < 0 {
		PrintUsageWithExit()
	}

	if toolFlags.Debug != "" {
		stat, err1 := os.Stat(toolFlags.Debug)
		if err1 != nil {
			fmt.Printf("debug path not existing: %s", toolFlags.Debug)
			return
		}
		if !stat.IsDir() {
			fmt.Printf("debug path must be a directory: %s", toolFlags.Debug)
			return
		}
	}

	// only enhance the "compile" phase
	cmdName := tools.ParseProxyCommandName(args, firstNonOptionIndex)
	if cmdName != "compile" {
		executeDelegateCommand(args[firstNonOptionIndex:])
		return
	}

	// loading config
	if err1 := config.LoadConfig(toolFlags.Config); err1 != nil {
		log.Fatalf("loading config file error: %s", err1)
	}

	// parse the args
	compileOptions := &api.CompileOptions{}
	if _, err = tools.ParseFlags(compileOptions, args); err != nil {
		executeDelegateCommand(args[firstNonOptionIndex:])
		return
	}

	// execute the enhancement
	args, err = instrument.Execute(compileOptions, args)
	if err != nil {
		log.Fatal(err)
	}

	// execute the delegate command with updated args
	executeDelegateCommand(args[firstNonOptionIndex:])
}