func realMain()

in main.go [721:799]


func realMain(ctx context.Context, cfg config.Config, batch, mockMeta, plainUI, genMapFile bool, profileType string, effectiveCLI string, tfClientPluginPath string) (result error) {
	switch strings.ToLower(profileType) {
	case "cpu":
		defer profile.Start(profile.CPUProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
	case "mem":
		defer profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
	}

	// Initialize the TFClient
	if tfClientPluginPath != "" {
		// #nosec G204
		cmd := exec.Command(flagset.hflagTFClientPluginPath)
		cmd.Env = append(cmd.Env,
			// Disable AzureRM provider's enahnced validation, which will cause RP listing, that is expensive.
			// The setting for with_tf version is done during the init_tf function of meta Init phase.
			"ARM_PROVIDER_ENHANCED_VALIDATION=false",
			// AzureRM provider will honor env.var "AZURE_HTTP_USER_AGENT" when constructing for HTTP "User-Agent" header.
			// The setting for with_tf version is done during the init_tf function of meta Init phase.
			"AZURE_HTTP_USER_AGENT="+cfg.AzureSDKClientOption.Telemetry.ApplicationID,
		)
		tfc, err := tfclient.New(tfclient.Option{
			Cmd:    cmd,
			Logger: slog2hclog.New(cfg.Logger.WithGroup("provider"), nil),
		})
		if err != nil {
			return err
		}
		cfg.TFClient = tfc
	}

	tc := cfg.TelemetryClient

	defer func() {
		if result == nil {
			cfg.Logger.Info("aztfexport ends")
			tc.Trace(telemetry.Info, "aztfexport ends")
		} else {
			cfg.Logger.Error("aztfexport ends with error", "error", result)
			tc.Trace(telemetry.Error, fmt.Sprintf("aztfexport ends with error"))
			tc.Trace(telemetry.Error, fmt.Sprintf("Error detail: %v", result))
		}
		tc.Close()
	}()

	cfg.Logger.Info("aztfexport starts", "config", fmt.Sprintf("%#v", cfg))
	tc.Trace(telemetry.Info, "aztfexport starts")
	tc.Trace(telemetry.Info, "Effective CLI: "+effectiveCLI)

	// Run in non-interactive mode
	if batch {
		nicfg := internalconfig.NonInteractiveModeConfig{
			MockMeta:           mockMeta,
			Config:             cfg,
			PlainUI:            plainUI,
			GenMappingFileOnly: genMapFile,
		}
		if err := internal.BatchImport(ctx, nicfg); err != nil {
			result = err
			return
		}
		return nil
	}

	// Run in interactive mode
	icfg := internalconfig.InteractiveModeConfig{
		Config:   cfg,
		MockMeta: mockMeta,
	}
	prog, err := ui.NewProgram(ctx, icfg)
	if err != nil {
		result = err
		return
	}
	if err := prog.Start(); err != nil {
		result = err
		return
	}
	return nil
}