How chmln/sd works
Main components
• Core Application (CLI Entry Point): Represented by src/main.rs. This module orchestrates the entire application.
• CLI Parsing & Input Processing: Implemented in src/cli.rs and src/input.rs. These modules handle command-line argument parsing and reading file/console input.
• Replacer Module: Found in src/replacer (with mod.rs, tests.rs, validate.rs). It encapsulates the core logic of text search and replace, whether in regex mode or in string-literal mode.
• Error Handling: The error.rs module centralizes error creation and propagation throughout the tool.
• Auxiliary Build/Generation Tasks: The xtask directory (with its own Cargo.toml and source files) is used for tasks like generating shell completions and the manual page (found in gen/). This indicates a separation between production code and build tooling.
• Testing Infrastructure: The tests folder, along with snapshot tests and proptest-regressions, ensures the correctness of the replace operations and overall CLI behavior.
• Configuration & Build Files: Cargo.toml, Cargo.lock, rustfmt, and other configuration files define dependencies, formatting, and the Rust build system. They illustrate the project’s integration with Cargo and CI/CD configuration files under .github.
Mapping Relationships and Flow
• The CLI module (src/cli.rs) processes user inputs (command-line parameters, flags, and file names) and passes them to the input processor.
• The Input module (src/input.rs) reads data (from STDIN or files) and sends it to the Replacer module.
• The Replacer module (in src/replacer/) executes the core find and replace logic, handling both regex and fixed-string modes. It also manages capture groups and formats output as described.
• Any errors detected in processing are handled by the Error module (src/error.rs) and reported back to the user.
• Optionally, the xtask component (xtask/src) is used in the build process to generate artifacts (e.g., shell completions in gen/completions, the man page in gen/sd.1).
• Testing components ensure that each of these stages works as intended; tests are structured to validate CLI commands and scenario-based outputs.
Final Checklist
• All major components are boxed and labeled.
• Annotations or notes on:
• The use of regex vs. string-literal modes.
• How errors are handled.
• Build and test infrastructure supporting the project.