func main()

in cmd/gitlab-zoekt/main.go [34:88]


func main() {
	if len(os.Args) < 2 {
		printHelp()
		os.Exit(1)
	}

	command := os.Args[1]

	// Handle help flags at the top level
	if command == "help" || command == "-help" || command == "--help" || command == "-h" {
		printHelp()
		os.Exit(0)
	}

	// Handle version command at the top level
	if command == "version" {
		fmt.Printf("%s %s (built at: %s)\n", os.Args[0], Version, BuildTime) // nolint:forbidigo
		os.Exit(0)
	}

	// Shift the arguments to allow flags to be parsed correctly for subcommands
	// This makes it so that gitlab-zoekt indexer -index_dir=/data/index looks like
	// the original gitlab-zoekt-indexer -index_dir=/data/index
	//
	// We keep the original program name (argv[0]) but pass all other arguments
	// (including version flags) to the underlying mode implementation
	shiftedArgs := []string{os.Args[0]}
	if len(os.Args) > 2 {
		shiftedArgs = append(shiftedArgs, os.Args[2:]...)
	}
	os.Args = shiftedArgs

	// Reset flag parse state
	flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)

	// Run the appropriate command
	switch strings.ToLower(command) {
	case "indexer":
		err := runIndexer()
		if err != nil {
			slog.Error("program aborted", "error", err)
			os.Exit(1)
		}
	case "webserver":
		err := runWebserver()
		if err != nil {
			slog.Error("program aborted", "error", err)
			os.Exit(1)
		}
	default:
		fmt.Fprintf(os.Stderr, "Unknown command: %s\n\n", command)
		printHelp()
		os.Exit(1)
	}
}