Skip to content

Commit

Permalink
template checking
Browse files Browse the repository at this point in the history
  • Loading branch information
bestia.dev committed Apr 22, 2024
1 parent d97238c commit d0cde66
Show file tree
Hide file tree
Showing 35 changed files with 812 additions and 1,141 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-auto"
version = "2024.419.1824"
version = "2024.422.15"
authors = ["bestia.dev"]
homepage = "https://bestia.dev"
edition = "2021"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[//]: # (auto_cargo_toml_to_md start)

**Automation tasks coded in Rust language for the workflow of Rust projects**
***version: 2024.419.1824 date: 2024-04-19 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/cargo-auto)***
***version: 2024.422.15 date: 2024-04-22 author: [bestia.dev](https://bestia.dev) repository: [GitHub](https://github.com/automation-tasks-rs/cargo-auto)***

![maintained](https://img.shields.io/badge/maintained-green)
![ready-for-use](https://img.shields.io/badge/ready_for_use-green)
Expand All @@ -28,11 +28,11 @@
![cargo-auto](https://bestia.dev/webpage_hit_counter/get_svg_image/959103982.svg)

[//]: # (auto_lines_of_code start)
[![Lines in Rust code](https://img.shields.io/badge/Lines_in_Rust-3106-green.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in Rust code](https://img.shields.io/badge/Lines_in_Rust-3142-green.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in Doc comments](https://img.shields.io/badge/Lines_in_Doc_comments-1191-blue.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in Comments](https://img.shields.io/badge/Lines_in_comments-699-purple.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in Comments](https://img.shields.io/badge/Lines_in_comments-704-purple.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in examples](https://img.shields.io/badge/Lines_in_examples-0-yellow.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in tests](https://img.shields.io/badge/Lines_in_tests-10704-orange.svg)](https://github.com/automation-tasks-rs/cargo-auto/)
[![Lines in tests](https://img.shields.io/badge/Lines_in_tests-10869-orange.svg)](https://github.com/automation-tasks-rs/cargo-auto/)

[//]: # (auto_lines_of_code end)

Expand Down
6 changes: 3 additions & 3 deletions automation_tasks_rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ fn task_release() {
{YELLOW}1. Check if the template `new_cli` is working. Open a new terminal in VSCode and run:{RESET}
{GREEN}cd ~/rustprojects{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_cli hello_world;{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_cli hello_world bestia.dev;{RESET}
{GREEN}code hello_world{RESET}
{YELLOW}In the new VSCODE window terminal, first change in Cargo.toml/repository from "github_owner" to your github username.{RESET}
{YELLOW} Then try the workflow: cargo auto build, cargo auto release, cargo auto doc,... all to the end.{RESET}
Expand All @@ -286,7 +286,7 @@ fn task_release() {
{YELLOW}2. Check if the template `new_wasm` is working. Open a new terminal in VSCode and run:{RESET}
{GREEN}cd ~/rustprojects{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_wasm hello_world{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_wasm hello_world bestia.dev luciano_bestia;{RESET}
{GREEN}code hello_world{RESET}
{YELLOW}In the new VSCODE window terminal, first change in Cargo.toml/repository from "github_owner" to your github username.{RESET}
{YELLOW} Then try the workflow: cargo auto build, cargo auto release, cargo auto doc,... all to the end.{RESET}
Expand All @@ -295,7 +295,7 @@ fn task_release() {
{YELLOW}3. Check if the template `new_pwa_wasm` is working. Open a new terminal in VSCode and run:{RESET}
{GREEN}cd ~/rustprojects{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_pwa_wasm hello_world{RESET}
{GREEN}./cargo-auto/target/release/{package_name} new_pwa_wasm{RESET}
{YELLOW}Follow the instructions{RESET}
{YELLOW}If ok, close the VSCode window.{RESET}
Expand Down
44 changes: 28 additions & 16 deletions automation_tasks_rs/src/secrets_always_local_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,7 @@ pub(crate) mod ssh_mod {
)
}

let identity_private_file_path_expanded = cargo_auto_encrypt_secret_lib::file_path_home_expand(identity_private_file_path);
if !camino::Utf8Path::new(&identity_private_file_path_expanded).exists() {
eprintln!("{RED}Identity file {identity_private_file_path_expanded} that contains the SSH private key does not exist! {RESET}");
eprintln!(" {YELLOW}Create the SSH key manually in bash with this command:{RESET}");
if identity_private_file_path_expanded.as_str().contains("github_api") {
eprintln!(r#"{GREEN}ssh-keygen -t ed25519 -f \"{identity_private_file_path_expanded}\" -C \"github api token\"{RESET}"#);
} else if identity_private_file_path_expanded.as_str().contains("github_api") {
eprintln!(r#"{GREEN}ssh-keygen -t ed25519 -f \"{identity_private_file_path_expanded}\" -C \"crates io token\"{RESET}"#);
}
eprintln!(" ");
panic!("{RED}Error: File {identity_private_file_path_expanded} does not exist! {RESET}");
}
let identity_private_file_path_expanded = expand_path_check_private_key_exists(identity_private_file_path);

let fingerprint_from_file = cargo_auto_encrypt_secret_lib::get_fingerprint_from_file(&identity_private_file_path_expanded);

Expand Down Expand Up @@ -282,6 +271,24 @@ pub(crate) mod ssh_mod {
}
}
}
/// Expand path and check if identity file exists
///
/// Inform the user how to generate identity file.
pub fn expand_path_check_private_key_exists(identity_private_file_path: &camino::Utf8Path) -> camino::Utf8PathBuf {
let identity_private_file_path_expanded = cargo_auto_encrypt_secret_lib::file_path_home_expand(identity_private_file_path);
if !camino::Utf8Path::new(&identity_private_file_path_expanded).exists() {
eprintln!("{RED}Identity file {identity_private_file_path_expanded} that contains the SSH private key does not exist! {RESET}");
eprintln!(" {YELLOW}Create the SSH key manually in bash with this command:{RESET}");
if identity_private_file_path_expanded.as_str().contains("github_api") {
eprintln!(r#"{GREEN}ssh-keygen -t ed25519 -f "{identity_private_file_path_expanded}" -C "github api token"{RESET}"#);
} else if identity_private_file_path_expanded.as_str().contains("crates_io") {
eprintln!(r#"{GREEN}ssh-keygen -t ed25519 -f "{identity_private_file_path_expanded}" -C "crates io token"{RESET}"#);
}
eprintln!(" ");
panic!("{RED}Error: File {identity_private_file_path_expanded} does not exist! {RESET}");
}
identity_private_file_path_expanded
}
}

pub(crate) mod github_mod {
Expand Down Expand Up @@ -365,7 +372,9 @@ pub(crate) mod github_mod {
let encrypted_string_file_path = camino::Utf8Path::new("~/.ssh/github_api_token_encrypted.txt");
let encrypted_string_file_path_expanded = cargo_auto_encrypt_secret_lib::file_path_home_expand(encrypted_string_file_path);

let identity_file_path = camino::Utf8Path::new("~/.ssh/github_api_token_ssh_1");
let identity_private_file_path = camino::Utf8Path::new("~/.ssh/github_api_token_ssh_1");
let _identity_private_file_path_expanded = crate::secrets_always_local_mod::ssh_mod::expand_path_check_private_key_exists(identity_private_file_path);

if !encrypted_string_file_path_expanded.exists() {
// ask interactive
println!(" {BLUE}Do you want to store the GitHub API token encrypted with an SSH key? (y/n){RESET}");
Expand All @@ -377,7 +386,7 @@ pub(crate) mod github_mod {
// get the passphrase and token interactively
let mut ssh_context = super::ssh_mod::SshContext::new();
// encrypt and save the encrypted token
cargo_auto_encrypt_secret_lib::encrypt_with_ssh_interactive_save_file(&mut ssh_context, identity_file_path, encrypted_string_file_path);
cargo_auto_encrypt_secret_lib::encrypt_with_ssh_interactive_save_file(&mut ssh_context, identity_private_file_path, encrypted_string_file_path);
// read the token and decrypt, return GitHubClient
read_token_and_decrypt_return_github_client(ssh_context, encrypted_string_file_path)
}
Expand Down Expand Up @@ -553,7 +562,10 @@ pub(crate) mod crate_io_mod {
let encrypted_string_file_path = camino::Utf8Path::new("~/.ssh/crates_io_token_encrypted.txt");
let encrypted_string_file_path_expanded = cargo_auto_encrypt_secret_lib::file_path_home_expand(encrypted_string_file_path);

let identity_file_path = camino::Utf8Path::new("~/.ssh/crates_io_token_ssh_1");
let identity_private_file_path = camino::Utf8Path::new("~/.ssh/crates_io_token_ssh_1");

let _identity_private_file_path_expanded = crate::secrets_always_local_mod::ssh_mod::expand_path_check_private_key_exists(identity_private_file_path);

if !encrypted_string_file_path_expanded.exists() {
// ask interactive
println!(" {BLUE}Do you want to store the crates.io token encrypted with an SSH key? (y/n){RESET}");
Expand All @@ -565,7 +577,7 @@ pub(crate) mod crate_io_mod {
// get the passphrase and token interactively
let mut ssh_context = super::ssh_mod::SshContext::new();
// encrypt and save the encrypted token
cargo_auto_encrypt_secret_lib::encrypt_with_ssh_interactive_save_file(&mut ssh_context, identity_file_path, encrypted_string_file_path);
cargo_auto_encrypt_secret_lib::encrypt_with_ssh_interactive_save_file(&mut ssh_context, identity_private_file_path, encrypted_string_file_path);
// read the token and decrypt, return CratesIoClient
read_token_and_decrypt_return_crate_io_client(ssh_context, encrypted_string_file_path)
}
Expand Down
23 changes: 16 additions & 7 deletions src/outside_of_rust_project_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ fn print_help_from_cargo_auto() {
This program automates your custom tasks when developing a Rust project.{RESET}
{YELLOW}Outside of a Rust project, cargo-auto can create a new Rust project:{RESET}
{GREEN}cargo auto new_cli project_name{RESET}{YELLOW} - a simple yet complete CLI application, better then `cargo new`{RESET}
{GREEN}cargo auto new_wasm project_name{RESET}{YELLOW} - a complete wasm application that works inside the browser{RESET}
{GREEN}cargo auto new_pwa_wasm project_name{RESET}{YELLOW} - On first call, it will create the `pwa.json5` and `icon512x512.png` files.{RESET}
{GREEN}cargo auto new_cli project_name github_owner{RESET}{YELLOW} - a simple yet complete CLI application, better then `cargo new`{RESET}
{GREEN}cargo auto new_wasm project_name github_owner web_server_domain server_username{RESET}{YELLOW} - a complete wasm application that works inside the browser{RESET}
{GREEN}cargo auto new_pwa_wasm {RESET}{YELLOW} - On first call, it will create the `pwa.json5` and `icon512x512.png` files.{RESET}
{YELLOW}Modify them with the required data for your pwa project and then repeat the same command.{RESET}
{YELLOW}© 2024 bestia.dev MIT License github.com/automation-tasks-rs/cargo-auto{RESET}
Expand All @@ -58,14 +58,23 @@ fn match_first_argument(task: &str, args: &mut std::env::Args) {
if task == "completion" {
completion();
} else if task == "new_cli" {
// project_name
let arg_2 = args.next();
crate::template_new_cli_mod::new_cli(arg_2);
// github_owner
let arg_3 = args.next();
crate::template_new_cli_mod::new_cli(arg_2, arg_3);
} else if task == "new_wasm" {
// project_name
let arg_2 = args.next();
crate::template_new_wasm_mod::new_wasm(arg_2);
// github_owner
let arg_3 = args.next();
// web server URL
let arg_4 = args.next();
// web server username
let arg_5 = args.next();
crate::template_new_wasm_mod::new_wasm(arg_2, arg_3, arg_4, arg_5);
} else if task == "new_pwa_wasm" {
let arg_2 = args.next();
crate::template_new_pwa_wasm_mod::new_pwa_wasm(arg_2);
crate::template_new_pwa_wasm_mod::new_pwa_wasm();
} else {
print_help_from_cargo_auto();
}
Expand Down
11 changes: 7 additions & 4 deletions src/template_new_auto_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub fn get_vec_file() -> Vec<crate::FileItem> {
// region: files copied into strings by automation tasks
vec_file.push(crate::FileItem {
file_name: "rustfmt.toml",
file_content: r###"max_width = 200"###,
file_content: r###"max_width = 200
"###,
});
vec_file.push(crate::FileItem {
file_name: ".gitignore",
Expand Down Expand Up @@ -140,8 +141,8 @@ pub fn tracing_init() {
// Unset the environment variable RUST_LOG
// unset RUST_LOG
let filter = tracing_subscriber::EnvFilter::from_default_env()
.add_directive("hyper_util=error".parse().unwrap())
.add_directive("reqwest=error".parse().unwrap());
.add_directive("hyper_util=error".parse().unwrap_or_else(|e| panic!("{e}")))
.add_directive("reqwest=error".parse().unwrap_or_else(|e| panic!("{e}")));
tracing_subscriber::fmt()
.with_file(true)
Expand Down Expand Up @@ -258,12 +259,14 @@ fn print_help() {
/// all example commands in one place
fn print_examples_cmd() {
/*
println!(
r#"
{YELLOW}run examples:{RESET}
{GREEN}cargo run --example plantuml1{RESET}
"#
);
*/
}
/// sub-command for bash auto-completion of `cargo auto` using the crate `dev_bestia_cargo_completion`
Expand Down Expand Up @@ -360,7 +363,7 @@ fn task_doc() {
.run().unwrap_or_else(|e| panic!("{e}"));
// pretty html
cl::auto_doc_tidy_html().unwrap();
cl::auto_doc_tidy_html().unwrap_or_else(|e| panic!("{e}"));
cl::run_shell_command_static("cargo fmt").unwrap_or_else(|e| panic!("{e}"));
// message to help user with next move
println!(
Expand Down
Loading

0 comments on commit d0cde66

Please sign in to comment.