Crate cargo_auto_lib

Source
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

maintained ready-for-use rustlang automation workflow

logo cargo_auto_lib is part of the automation_tasks_rs project

crates.io Documentation crev reviews Lib.rs
License Rust Newest docs cargo_auto_lib

Lines in Rust code Lines in Doc comments Lines in Comments Lines in examples Lines in tests

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§

CargoToml
Read data from Cargo.toml.
Read data from Cargo.toml.
ShellCommandLimitedDoubleQuotesSanitizer
Shell command builder with simple but limited sanitizer.
ShellOutput
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§

BLUE
ANSI color
GREEN
ANSI color
RED
ANSI color
RESET
ANSI color
YELLOW
ANSI color

Traits§

CargoTomlPublicApiMethods
Trait with methods to read data from Cargo.toml.
ShellCommandLimitedDoubleQuotesSanitizerTrait
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§

ResultWithLibError
Result type with fixed LibError using thiserror.