opengrep 1.1.0

Advanced AST-aware code search tool with tree-sitter parsing and AI integration capabilities
Documentation
//! OpenGrep: An advanced, AST-aware code search tool.
#![deny(unsafe_code)]

use anyhow::Result;
use clap::Parser;
use opengrep::{
    cli::Cli,
    config::Config,
    init_logging,
    output::{create_formatter, OutputFormat},
    search::SearchEngine,
    VERSION,
};
use std::io::stdout;
use std::process;

#[tokio::main]
async fn main() -> Result<()> {
    // Parse command-line arguments
    let cli = Cli::parse();

    // Handle special commands like version
    if cli.version {
        println!("opengrep {}", VERSION);
        process::exit(0);
    }

    // Handle list languages
    if cli.list_languages {
        opengrep::parsers::list_supported_languages();
        process::exit(0);
    }

    // Initialize logging
    let verbosity = cli.verbose;
    init_logging(verbosity)?;

    // Validate CLI arguments
    cli.validate()?;

    // Handle interactive mode
    if cli.interactive {
        let config = Config::from_cli(&cli)?;
        let engine = SearchEngine::new(config);
        let results = engine.interactive_search().await?;
        
        // Print results using text formatter
        let formatter = create_formatter(OutputFormat::Text);
        let mut writer = stdout();
        formatter.format(&results, &mut writer, &Default::default())?;
        
        return Ok(());
    }

    // Load configuration
    let config = Config::from_cli(&cli)?;

    // Get pattern and paths from CLI
    let pattern = &cli.pattern;
    let paths = if cli.paths.is_empty() {
        vec![std::path::PathBuf::from(".")]
    } else {
        cli.paths.clone()
    };

    // Create and run the search engine
    let engine = SearchEngine::new(config.clone());
    let results = engine.search(pattern, &paths).await?;

    // Format and print the output
    let output_format = match cli.output_format {
        opengrep::cli::OutputFormat::Text => OutputFormat::Text,
        opengrep::cli::OutputFormat::Json => OutputFormat::Json,
        opengrep::cli::OutputFormat::Html => OutputFormat::Html,
        opengrep::cli::OutputFormat::Xml => OutputFormat::Xml,
        opengrep::cli::OutputFormat::Csv => OutputFormat::Csv,
    };
    let formatter = create_formatter(output_format);
    let mut writer = stdout();
    formatter.format(&results, &mut writer, &config.output)?;

    Ok(())
}