func runGetComments()

in cmd/get_comments.go [36:77]


func runGetComments(cmd *cobra.Command, args []string) error {
	if err := validateDialect(dialect); err != nil {
		return err
	}

	dbConfig := database.GetConfig()
	if dbConfig == nil {
		return fmt.Errorf("database config is not initialized")
	}

	outputFile := cmd.Flag("out_file").Value.String()
	if outputFile == "" {
		outputFile = utils.GetDefaultOutputFilePath(dbConfig.DBName, "get-comments")
	}

	log.Println("INFO: Starting get-comments operation",
		"dialect:", dialect,
		"database:", dbName,
	)

	db, err := setupDatabase()
	if err != nil {
		return err
	}
	defer db.Close()

	metadataCollector := enricher.NewMetadataCollector(db, &enricher.DefaultRetryOptions, dryRun, geminiAPIKey, "", "")
	ctx := cmd.Context()
	comments, err := metadataCollector.GetComments(ctx)
	if err != nil {
		return fmt.Errorf("failed to retrieve comments: %w", err)
	}

	output := enricher.FormatCommentsAsText(comments)
	if err := enricher.WriteCommentsToFile(output, outputFile); err != nil {
		return fmt.Errorf("failed to write comments to file: %w", err)
	}
	fmt.Printf("Comments written to: %s\n", outputFile)

	log.Println("INFO: Get comments operation completed")
	return nil
}