forge-scriptgen is a small Rust CLI that turns Solidity contracts in a Foundry project into starter deployment scripts.
Current flow:
- Parse CLI arguments in
src/main.rs - Resolve the contracts directory and output directory
- Discover Solidity files under
src/**/*.sol - Parse contracts and constructor metadata through a parser backend
- Select the target contract
- Collect constructor arguments from JSON or interactive input
- Render and write
script/<ContractName>.s.sol
The CLI currently lives in src/main.rs. It is responsible for:
- argument parsing
- user-facing errors
- interactive prompts
- file discovery
- script rendering and file writing
The project already has a parser boundary:
ParserBackendContractParserStringWalkerParser
This keeps the CLI flow independent from a specific parsing implementation and allows an AST-based backend to be added later.
StringWalkerParser is a source-walking parser that relies on:
- comment stripping
- delimiter tracking
- string tracking
- contract and constructor keyword scanning
It is intentionally lightweight, but it is expected to preserve behavior across a range of Solidity patterns covered by tests and fixtures.
Important structures:
Options: parsed CLI inputsContractInfo: selected contract metadata used for generationConstructorParam: constructor parameter text plus detected display nameParsedContract: parser output before file-level metadata is attached
discover_contracts_with_parser(...) is the main bridge between file discovery and parser output.
There are three layers of validation:
-
Unit tests in
src/main.rs- parser helpers
- constructor extraction
- argument parsing behavior
-
CLI integration tests in
tests/cli.rs- end-to-end CLI behavior against temporary projects
-
Reproducible fixture demo in
tests/fixtures/repro/andscripts/reproduce_complex_cli_demo.sh- complex Solidity source examples
- committed expected generated output
Current priorities:
- generated script correctness over aggressive automation
- explicit handling of complex constructor literals
- minimal friction for Foundry users
- backward-compatible room for a future AST parser
Known limitation:
- the current parser is not semantic AST parsing yet, so literal correctness still depends on user input for complex types