|
| 1 | +# rust-code-analysis-cli |
| 2 | + |
| 3 | +`rust-code-analysis-cli` is a tool designed to compute and export code metrics, analyze source code, and perform various operations such as removing comments, counting nodes, retrieving functions, and computing code metrics in different formats. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Analyze source code for different programming languages. |
| 8 | +- Export results in different formats (CBOR, JSON, TOML, YAML). |
| 9 | +- Perform various operations on source code (e.g., dumping abstract syntax tree to stdout, count nodes, computing code metrics). |
| 10 | + |
| 11 | +## Project Structure |
| 12 | + |
| 13 | +```sh |
| 14 | +rust-code-analysis-cli |
| 15 | +├── Cargo.toml # Project metadata and dependencies |
| 16 | +└── src |
| 17 | + ├── formats.rs # Handles format-specific output (CBOR, JSON, TOML, YAML) |
| 18 | + └── main.rs # Main logic for command-line operations and code analysis |
| 19 | +``` |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +To use this tool, you need to have Rust installed on your system. |
| 24 | + |
| 25 | +Clone the repository and run the following command: |
| 26 | + |
| 27 | +```sh |
| 28 | +cd rust-code-analysis-cli/ |
| 29 | +cargo build --debug # or cargo build --release |
| 30 | +``` |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +Run the tool by specifying the input file and the desired operation: |
| 35 | + |
| 36 | +```sh |
| 37 | +cargo run -- [OPTIONS] |
| 38 | +``` |
| 39 | + |
| 40 | +## Available Options |
| 41 | + |
| 42 | +- `-p, --paths <FILE>...`: Input files to analyze. |
| 43 | +- `-d, --dump`: Dump the abstract syntax tree to stdout. |
| 44 | +- `-c, --comments`: Remove comments from specified files. |
| 45 | +- `-f, --find <NODE_TYPE>`: Find nodes of the given type. |
| 46 | +- `-F, --function`: Get functions and their spans. |
| 47 | +- `-C, --count <NODE_TYPE>`: Count nodes of the given type. |
| 48 | +- `-m, --metrics`: Compute code metrics. |
| 49 | +- `--ops`: Retrieve all operands and operators in the code. |
| 50 | +- `-i, --in-place`: Do actions in place. |
| 51 | +- `-I, --include [<INCLUDE>...]`: Include files matching the given pattern. |
| 52 | +- `-X, --exclude [<EXCLUDE>...]`: Exclude files matching the given pattern. |
| 53 | +- `-j, --num-jobs <NUM_JOBS>`: Number of threads to use. |
| 54 | +- `-l, --language-type <LANGUAGE>`: Language of the input files. |
| 55 | +- `-O, --output-format <FORMAT>`: Output format for the results (CBOR, JSON, TOML, YAML). |
| 56 | +- `--pr`: Dump a pretty json output file. |
| 57 | +- `-o, --output <OUTPUT>`: Output directory for the results. |
| 58 | +- `--preproc <PREPROCESSOR>`: Get preprocessor directives for C/C++ files. |
| 59 | +- `--ls <LINE_START>`: Start line for the analysis. |
| 60 | +- `--le <LINE_END>`: End line for the analysis. |
| 61 | +- `-w, --warning`: Show warnings. |
| 62 | +- `-v, --version`: Show version information. |
| 63 | +- `-h, --help`: Show help information. |
| 64 | + |
| 65 | +## Examples |
| 66 | + |
| 67 | +To analyze the code in a file and export the metrics in JSON format: |
| 68 | + |
| 69 | +```sh |
| 70 | +cargo run -- --metrics --output-format json --output . --paths path/to/file.rs |
| 71 | +``` |
0 commit comments