88- Available as both Rust and Python package
99- CLI and library interfaces
1010- stdin/stdout support for pipeline usage
11+ - Configuration file support (` qasmfmt.toml ` )
12+ - Directory recursive processing
1113
1214## Installation
1315
@@ -35,33 +37,82 @@ cargo install --path .
3537
3638### CLI
3739
40+ ``` bash
41+ qasmfmt [OPTIONS] [PATH]...
42+ ```
43+
44+ #### Modes (mutually exclusive)
45+
46+ | Option | Description |
47+ | --------| -------------|
48+ | ` -w, --write ` | Write formatted output back to files (in-place) |
49+ | ` --check ` | Check if files are formatted (exit 1 if not) |
50+ | ` --diff ` | Show unified diff of formatting changes (exit 1 if diff exists) |
51+
52+ #### Options
53+
54+ | Option | Description |
55+ | --------| -------------|
56+ | ` -i, --indent <N> ` | Indentation size in spaces (default: 4) |
57+ | ` --max-width <N> ` | Maximum line width (default: 100) |
58+ | ` --stdin-filename <PATH> ` | Virtual filename for stdin input |
59+ | ` --config <PATH> ` | Path to configuration file |
60+ | ` --no-config ` | Disable automatic configuration file discovery |
61+ | ` -V, --version ` | Print version |
62+ | ` -h, --help ` | Print help |
63+
64+ #### Examples
65+
3866``` bash
3967# Format file (print to stdout)
4068qasmfmt input.qasm
4169
4270# Format file in-place
4371qasmfmt -w input.qasm
44- qasmfmt --write input.qasm
4572
4673# Check if file is formatted (for CI)
47- qasmfmt -c input.qasm
4874qasmfmt --check input.qasm
4975
5076# Show diff
51- qasmfmt -d input.qasm
5277qasmfmt --diff input.qasm
5378
5479# Format from stdin
5580echo ' OPENQASM 3.0;qubit[2]q;' | qasmfmt
81+ echo ' OPENQASM 3.0;qubit[2]q;' | qasmfmt -
82+
83+ # Format from stdin with virtual filename
84+ echo ' OPENQASM 3.0;qubit[2]q;' | qasmfmt --stdin-filename circuit.qasm -
5685
5786# Custom indent size
5887qasmfmt -i 2 input.qasm
59- qasmfmt --indent 2 input.qasm
6088
61- # Format multiple files
62- qasmfmt -w * .qasm
89+ # Format all .qasm files in a directory (recursive)
90+ qasmfmt -w ./circuits/
91+
92+ # Check all .qasm files in a directory
93+ qasmfmt --check ./src/
94+
95+ # Use specific config file
96+ qasmfmt --config ./qasmfmt.toml input.qasm
97+
98+ # Disable config file auto-discovery
99+ qasmfmt --no-config input.qasm
63100```
64101
102+ ### Configuration File
103+
104+ qasmfmt automatically searches for ` qasmfmt.toml ` from the input file's directory upward.
105+
106+ ``` toml
107+ # qasmfmt.toml
108+ indent_size = 2
109+ max_width = 80
110+ indent_style = " spaces" # or "tabs"
111+ trailing_newline = true
112+ ```
113+
114+ CLI options override configuration file settings.
115+
65116### Python Library
66117
67118``` python
@@ -125,6 +176,14 @@ cx q[0], q[1];
125176c = measure q;
126177```
127178
179+ ## Exit Codes
180+
181+ | Code | Description |
182+ | ------| -------------|
183+ | 0 | Success |
184+ | 1 | Error or formatting differences found (` --check ` , ` --diff ` ) |
185+ | 2 | Usage error (e.g., mutually exclusive options, stdin with ` --write ` ) |
186+
128187## CI Integration
129188
130189### GitHub Actions
@@ -133,7 +192,7 @@ c = measure q;
133192- name : Check OpenQASM formatting
134193 run : |
135194 pip install qasmfmt
136- qasmfmt --check **/*.qasm
195+ qasmfmt --check .
137196` ` `
138197
139198### pre-commit
0 commit comments