예제 #1
0
func parseAnalyzerCommand() (string, []string, []string) {
	if *analyzerPort == 0 {
		port, err := netutil.PickUnusedPort()
		if err != nil {
			log.Fatalf("Failed to pick analyzer port: %v", err)
		}
		*analyzerPort = port
	}

	var i int
	for ; i < flag.NArg() && flag.Arg(i) != "--"; i++ {
	}

	args := constructArgs(flag.Args()[1:i], *analyzerPort)
	var compilations []string
	if i < flag.NArg() {
		compilations = flag.Args()[i+1:]
	}
	return flag.Arg(0), args, compilations
}
예제 #2
0
// parseAnalyzerCommand extracts the analyzer subcommand line from the current
// process's argument list, and replaces any occurrences of "@port@" in its
// command-line with the designated analyzer port. If no port is given, one is
// chosen and stored into *analyzerPort.
//
// The command and its arguments are returned, along with any trailing
// unclaimed arguments to use as compilation unit sources.
func parseAnalyzerCommand() (command string, args, compilations []string) {
	if *analyzerPort <= 0 {
		picked, err := netutil.PickUnusedPort()
		if err != nil {
			log.Fatalf("Failed to pick analyzer port: %v", err)
		}
		*analyzerPort = picked
	}

	// Find the breakpoint between the subcommand arguments and the trailing
	// arguments, if any.
	port := strings.NewReplacer("@port@", strconv.Itoa(*analyzerPort))
	for i, arg := range flag.Args() {
		if i == 0 {
			command = arg
		} else if arg == "--" {
			compilations = flag.Args()[i+1:]
			break
		} else {
			args = append(args, port.Replace(arg))
		}
	}
	return
}