func main()

in cmd/firebase/preparer/main.go [52:124]


func main() {
	// Flag parsing, ensuring that unknown flags are ignored and logged.
	flag.CommandLine.Init(flag.CommandLine.Name(), flag.ContinueOnError)
	if err := flag.CommandLine.Parse(os.Args[1:]); err != nil {
		log.Printf("Flag parsing error: %v.", err)
	}

	// Get any remaining arguments after flag parsing
	remainingArgs := flag.Args()
	if len(remainingArgs) > 0 {
		log.Printf("Ignored command-line arguments: %v", remainingArgs)
	}

	// Validate flag values are what we expect.
	if *projectID == "" {
		log.Fatal("--project_id flag not specified.")
	}

	if *appHostingYAMLOutputFilePath == "" {
		log.Fatal("--apphostingyaml_output_filepath flag not specified.")
	}

	if *dotEnvOutputFilePath == "" {
		log.Fatal("--dot_env_output_filepath flag not specified.")
	}

	if backendRootDirectory == nil {
		log.Fatal("--backend_root_directory flag not specified.")
	}

	if *buildpackConfigOutputFilePath == "" {
		log.Fatal("--buildpack_config_output_filepath flag not specified.")
	}

	// TODO: inlined - Add a check for region once it has rolled out in the backend.

	secretClient, err := secretmanager.NewClient(context.Background())
	if err != nil {
		log.Fatal(fmt.Errorf("failed to create secretmanager client: %w", err))
	}
	defer secretClient.Close()

	opts := preparer.Options{
		SecretClient:                      secretClient,
		AppHostingYAMLPath:                *apphostingYAMLFilePath,
		ProjectID:                         *projectID,
		Region:                            *region,
		EnvironmentName:                   *environmentName,
		AppHostingYAMLOutputFilePath:      *appHostingYAMLOutputFilePath,
		EnvDereferencedOutputFilePath:     *dotEnvOutputFilePath,
		BackendRootDirectory:              *backendRootDirectory,
		BuildpackConfigOutputFilePath:     *buildpackConfigOutputFilePath,
		FirebaseConfig:                    *firebaseConfig,
		FirebaseWebappConfig:              *firebaseWebappConfig,
		ServerSideEnvVars:                 *serverSideEnvVars,
		ApphostingPreprocessedPathForPack: *apphostingPreprocessedPathForPack,
	}

	gcpCtx := gcpbuildpack.NewContext()

	// Detect the apphosting.yaml path.
	opts.AppHostingYAMLPath, err = filesystem.DetectAppHostingYAMLPath(*workspacePath, *backendRootDirectory)

	if err != nil {
		gcpCtx.Exit(1, handleError(err))
	}

	if err = preparer.Prepare(context.Background(), opts); err != nil {
		gcpCtx.Exit(1, handleError(err))
	}

	gcpCtx.Exit(0, nil)
}