2 releases
0.1.1 | Nov 21, 2024 |
---|---|
0.1.0 | Nov 21, 2024 |
#520 in Command line utilities
265 downloads per month
9KB
disfmt
disfmt
is a simple CLI tool for reformatting Rust code by aligning {
, }
, and ;
symbols vertically. It processes your code to improve readability by ensuring these symbols are consistently aligned across lines.
Installation
You can easily install disfmt
using Cargo, the Rust package manager.
cargo install disfmt
This will install the disfmt
command globally, allowing you to use it from anywhere in your terminal.
Usage
Once installed, you can use the disfmt
tool via the command line to process Rust code. Here's the basic usage:
Aligning code from a file
disfmt input.rs -o output.rs
This will read the Rust code from input.rs
, align the {
, }
, and ;
symbols, and write the result to output.rs
.
Aligning code from stdin
You can also provide input through stdin and output the results to stdout:
cat input.rs | disfmt > output.rs
Or you can simply use:
disfmt input.rs
This will output the formatted code to the terminal (stdout).
Options
-o <output>
: Specify the output file to save the formatted code. If not provided, the result will write toSTDOUT
.input
: The input file to process. If not provided, the tool will read fromSTDIN
.
Example
fn parse_matches(matches: &clap::ArgMatches, cmd: &mut clap::Command, conn: &rusqlite::Connection) {
let subcommand = matches.subcommand().map_or_else(
|| {
cmd.print_help().ok() ;
std::process::exit(0) ;
} ,
|s| s ,
) ;
match subcommand.0 {
"add" => parse_add(matches, conn) ,
"list" => list_tasks_in_db(conn) ,
_ => {
eprintln!("Invalid subcommand") ;
cmd.print_help().ok() ;
std::process::exit(1) ;
Development
If you'd like to contribute to disfmt
, feel free to fork the repository and submit pull requests! Please make sure to run the tests before submitting changes.
Building the project
To build the project locally without installing, you can run:
cargo build --release
License
This project is licensed under the MIT License - see the LICENSE file for details.
Links
- GitHub repository: https://github.com/Muxutruk2/disfmt
- Documentation: https://docs.rs/disfmt
Dependencies
~1.1–1.7MB
~32K SLoC