Expand description
§cargo_auto_lib
Automation tasks coded in Rust language for the workflow of Rust projects
version: 3.0.14 date: 2025-03-29 author: Bestia.dev repository: GitHub
cargo_auto_lib is part of the automation_tasks_rs project
Hashtags: #maintained #ready-for-use #rustlang #automation #workflow
My projects on GitHub are more like a tutorial than a finished product: bestia-dev tutorials.
I recommend using the CRUSTDE - Containerized Rust Development Environment to write Rust projects on Linux, isolated from your system.
§Try it
First, install the tool for task automation in Rust projects:
cargo install cargo-auto
# Generate a new Rust CLI project:
cargo auto new_cli hello_world
# Open the `hello_world` project in VSCode:
code hello_world
# Open the generated directory `automation_tasks_rs` as an independent rust project in VSCode.
code hello_world/automation_tasks_rs
Now we can analyze the automation code. There is already this dependency inside Cargo.toml
for our library:
cargo_auto_lib="2.0.2"
Review the code in automation_tasks_rs/main.rs
. The cl::
namespace is the alias for cargo_auto_lib
.
Example:
/// cargo build --release
fn task_release() {
let cargo_toml = CargoToml::read();
cl::auto_version_increment_semver_or_date();
cl::auto_cargo_toml_to_md();
cl::auto_lines_of_code("");
cl::run_shell_command("cargo fmt");
cl::run_shell_command("cargo build --release");
println!(
r#"
{YELLOW}After `cargo auto release`, run the compiled binary, examples and/or tests{RESET}
{GREEN}./target/release/{package_name} arg_1{RESET}
{YELLOW}if ok then{RESET}
{GREEN}cargo auto doc{RESET}
"#,
package_name = cargo_toml.package_name(),
);
}
You can see this function will increment the version in Cargo.toml
.
Then it will copy some data from Cargo.toml
to README.md (title, description, version, author,…).
It will count the lines of code and create badges in README.md.
Then comes the traditional Rust part: cargo fmt and cargo build –release.
Finally, it will show on the screen the instructions on how to continue developing.
Run (in your main rust project):
cargo auto release
Now open the README.md and you will see the data that this automation task copied from other places. Therefore you change this data only in one place, the automation task copies them wherever needed.
§Panic!() and unwrap()
I want the tasks to exit immediately on any error. So I use unwrap() and panic!() a lot.
On purpose. And because I wrote this before I learned Rust error handling.
§Development details
Read the development details in a separate md file:
DEVELOPMENT.md
§Releases changelog
Read the release changelog in a separate md file:
RELEASES.md
§TODO
- remove the existing support for workspaces. Workspaces are a mess
- change it so that every member must have its own automation
- the workspace automation then calls the member’s automation
- It is better to have a non-workspace group of projects that are
- developed together using single workflow automation
§Open-source and free as a beer
My open-source projects are free as a beer (MIT license).
I just love programming.
But I need also to drink. If you find my projects and tutorials helpful, please buy me a beer by donating to my PayPal.
You know the price of a beer in your local bar ;-)
So I can drink a free beer for your health :-)
Na zdravje! Alla salute! Prost! Nazdravlje! 🍻
//bestia.dev
//github.com/bestia-dev
//bestiadev.substack.com
//youtube.com/@bestia-dev-tutorials
Re-exports§
pub use inquire;
Structs§
- Cargo
Toml - Read data from Cargo.toml.
Read data from Cargo.toml. - Shell
Command Limited Double Quotes Sanitizer - Shell command builder with simple but limited sanitizer.
- Shell
Output - Similar to std::process::Output, but with i32 and Strings for easier work. Similar to std::process::Output, but with i32 and Strings for easier work.
Constants§
Traits§
- Cargo
Toml Public ApiMethods - Trait with methods to read data from Cargo.toml.
- Shell
Command Limited Double Quotes Sanitizer Trait - Trait with methods for ShellCommandLimitedDoubleQuotesSanitizer.
Functions§
- add_
message_ to_ unreleased - Add commit message to Unreleased in RELEASES.md.
- auto_
cargo_ toml_ to_ md - This function includes data from Cargo.toml to markdown files.
- auto_
check_ micro_ xml - I want html pages to be correct microXML when I use them for single page application.
- auto_
delete_ old_ js_ snippets - Deletes old js snippets when working with wasm-pack.
- auto_
doc_ tidy_ html - Pretty HTML for docs.
- auto_
lines_ of_ code - This function inserts shield badges with lines_of_code into README.rs.
- auto_
md_ to_ doc_ comments - Finds rs files with markers and include segments from md files as doc comments.
- auto_
plantuml - Process plantuml in current directory.
- auto_
plantuml_ for_ path - Process plantuml for all md files.
- auto_
playground_ run_ code - Include the link to run code in Rust playground.
- auto_
semver_ increment_ minor - Increment the minor version in Cargo.toml file only if files are changed.
- auto_
semver_ increment_ minor_ forced - Increment the minor version in Cargo.toml file even if files are not changed.
- auto_
semver_ increment_ patch - Increment the patch version in Cargo.toml file only if files are changed.
- auto_
semver_ increment_ patch_ forced - Increment the patch version in Cargo.toml file even if files are not changed.
- auto_
version_ from_ date - New version from date is written to Cargo.toml and service_worker.js.
- auto_
version_ from_ date_ forced - Just like auto_version_from_date(), but force the new version even if no files are changed.
- auto_
version_ increment_ semver_ or_ date - Increment the version in Cargo.toml.
- auto_
version_ increment_ semver_ or_ date_ forced - Increment the version in Cargo.toml, forced.
- body_
text_ from_ releases_ md - Get release text from RELEASES.md.
- completion_
return_ one_ or_ more_ sub_ commands - Print one or more sub_commands.
- concatenate_
vec_ to_ string - The original
concat()
function does not have a delimiter. - copy_
folder_ files_ into_ module - Copy all files from the folder into a module as strings (static &str).
- create_
new_ version_ in_ releases_ md - Create a new Version title in RELEASES.md.
- exit_
if_ not_ run_ in_ rust_ project_ root_ directory - Check if the code was run inside the Rust project root directory.
- find_
from - Find ‘from pos’.
- find_
pos_ end_ data_ before_ delimiter - Return the position of end of the delimited data before the delimiter.
- find_
pos_ start_ data_ after_ delimiter - Return the position of start of the delimited data after the delimiter.
- git_
has_ remote - Does git have settings for remote.
- git_
is_ local_ repository - Check if this folder is a local Git repository.
- git_
tag_ sync_ check_ create_ push - Sync, check, create, push git tag.
- hash_
text - Hash text.
- home_
dir - Get home dir using the home crate.
- new_
local_ repository - Interactive ask to create a new local git repository.
- now_
utc_ date_ iso - UTC date in iso standard like 2024-12-31
- run_
shell_ command - Run one shell command.
- run_
shell_ command_ output - Run one shell command and return ShellOutput {exit_status, stdout, stderr}.
- run_
shell_ command_ static - Run one shell command with static str.
- run_
shell_ command_ success - Run one shell command and return true if success.
- tilde_
expand_ to_ home_ dir_ utf8 - Replace tilde with home::home_dir, only for utf8.
- traverse_
dir_ with_ exclude_ dir - Traverse dir and its sub-dir, but avoid excluded dirs.
Type Aliases§
- Result
With LibError - Result type with fixed LibError using thiserror.