Skip to main content

Crate duckduckgo_search_cli

Crate duckduckgo_search_cli 

Source
Expand description

§duckduckgo-search-cli

Rust CLI for searching DuckDuckGo via pure HTTP, with structured JSON output for LLM consumption. No paid API. No Chrome (during the search phase). No cache. Universal cross-platform (Linux including Alpine/NixOS/Flatpak/Snap, macOS including Apple Silicon, Windows including cmd.exe and PowerShell).

§Module Structure

ModuleResponsibility
cliClap structs (command-line argument parsing).
httpreqwest::Client construction and User-Agent selection.
searchURL building and HTTP request to the DuckDuckGo endpoint.
extractionHTML parsing with scraper and ad filtering.
pipelineSingle/multi orchestration, deduplication and source reading.
parallelMulti-query fan-out with JoinSet, Semaphore, CancellationToken.
outputJSON serialization and stdout writing (ONLY module with println!).
platformCross-platform initialization (UTF-8 on Windows, TTY detect).
typesShared structs and enums.
errorError codes and exit codes.
contentHTTP + readability extraction for --fetch-content (iter. 5).
fetch_conteudoParallel fan-out + per-host rate-limit (iter. 5 / 6).
selectorsLoading of external ConfiguracaoSeletores (iter. 6).
signalsCross-platform signal handlers (SIGPIPE, Ctrl+C).
config_initinit-config subcommand (iter. 6).
pathsPath validation and sanitization for I/O.
browserHeadless Chrome cross-platform under feature chrome (iter.7).

§Entry Point

The public function run is called by main.rs and returns an exit code as specified in section 17.7 of the specification.

Modules§

browser
Cross-platform detection and launch of headless Chrome via chromiumoxide.
cli
CLI argument definitions via clap derive.
config_init
Implements the init-config subcommand — copies TOMLs embedded in the binary to the user’s configuration directory, allowing local editing without recompiling.
content
Full text content extraction from URLs (flag --fetch-content).
error
Structured error codes as defined in specification section 14.3.
extraction
Extraction of search results from DuckDuckGo HTML.
fetch_conteudo
Parallel fan-out for content extraction (flag --fetch-content).
http
reqwest::Client construction and User-Agent selection.
output
Formatting and emission of the final result to stdout or a file.
parallel
Multi-query parallelism with JoinSet, Semaphore, staggered launch and CancellationToken.
paths
Path validation and sanitization for I/O operations.
pipeline
Orchestration of the CLI execution flow.
platform
Platform detection and cross-platform initialization.
search
URL construction and search request execution for DuckDuckGo.
selectors
Lazy loading of ConfiguracaoSeletores with precedence:
signals
Cross-platform signal handlers for the CLI binary.
types
Shared data types used across the application.

Functions§

run
Library entry point. Called by main.rs.