The midstr CLI tool is a simple Rust application that allows you to center a given text within a specified total length by adding padding characters on both sides. This can be useful for formatting text in various contexts.
midstr is part of my Rust Learning Series, where I explore Rust programming concepts and try to build various different tools and applications along the way.
To use midstr, follow the instructions below:
- Rust must be installed on your system.
Clone this repository to your local machine:
git clone https://github.com/your-username/midstr.git
Navigate to he project:
cd midstr
Build the application using Cargo:
cargo build --release
To center a text within a specified total length, use the following command format:
./target/release/midstr <total_length> <name> [fill_char]
- <total_length>: The total length of the resulting centered text.
- <name>: The text that you want to center.
- [fill_char] (optional): The character used for padding. Defaults to '-' if not provided.
./target/release/midstr 15 Hello *
This will produce the following output:
*** Hello ***
- If the number of arguments is incorrect, the application will display a usage message and exit.
- If the <total_length> argument is not a positive integer, an error message will be displayed.