From cd9b8d8642c9de8d1e34f7dfd7e32798e47a5610 Mon Sep 17 00:00:00 2001 From: Sebastien Rousseau Date: Sat, 16 Mar 2024 17:55:54 +0000 Subject: [PATCH] fix(libmake): :ambulance: gitignore, and optimisations --- .gitignore | 2 +- libmake.log | 2 -- src/generator.rs | 54 +++++++++++++++++++++++------------------------- 3 files changed, 27 insertions(+), 31 deletions(-) delete mode 100644 libmake.log diff --git a/.gitignore b/.gitignore index 0754afe..2571619 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.DS_Store *.profraw -ssg.log +*.log /.vscode/ /target/ build diff --git a/libmake.log b/libmake.log deleted file mode 100644 index cbbd4fa..0000000 --- a/libmake.log +++ /dev/null @@ -1,2 +0,0 @@ -SessionID=5869e75a-16e1-44bb-9ae5-c22fb22b1890 Timestamp=2024-03-16 17:39:36.784594 +00:00:00 Description=ASCII art generation event started. Level=INFO Component=deps -SessionID=5869e75a-16e1-44bb-9ae5-c22fb22b1890 Timestamp=2024-03-16 17:39:36.784594 +00:00:00 Description=ASCII art generation event completed. Level=INFO Component=deps diff --git a/src/generator.rs b/src/generator.rs index 054be93..d138ceb 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -5,8 +5,6 @@ use super::interface::replace_placeholders; use serde::{Deserialize, Serialize}; -use serde_json; -use serde_yaml; use std::{ fs, io, path::{Path, PathBuf}, @@ -267,7 +265,7 @@ pub fn create_template_folder() -> io::Result<()> { })?; // Write the file contents, trimming any leading or trailing newline characters - std::fs::write( + fs::write( &file_path, file_contents .trim_start_matches('\n') @@ -517,49 +515,49 @@ pub fn generate_from_csv(csv_path: &str) -> io::Result<()> { let record = result?; // println!("{:?}", record); let params = FileGenerationParams { - author: record.get(0).map(std::string::ToString::to_string), - build: record.get(1).map(std::string::ToString::to_string), + author: record.get(0).map(ToString::to_string), + build: record.get(1).map(ToString::to_string), categories: record .get(2) - .map(std::string::ToString::to_string), + .map(ToString::to_string), description: record .get(3) - .map(std::string::ToString::to_string), + .map(ToString::to_string), documentation: record .get(4) - .map(std::string::ToString::to_string), + .map(ToString::to_string), edition: record .get(5) - .map(std::string::ToString::to_string), - email: record.get(6).map(std::string::ToString::to_string), + .map(ToString::to_string), + email: record.get(6).map(ToString::to_string), homepage: record .get(7) - .map(std::string::ToString::to_string), + .map(ToString::to_string), keywords: record .get(8) - .map(std::string::ToString::to_string), + .map(ToString::to_string), license: record .get(9) - .map(std::string::ToString::to_string), - name: record.get(10).map(std::string::ToString::to_string), + .map(ToString::to_string), + name: record.get(10).map(ToString::to_string), output: record .get(11) - .map(std::string::ToString::to_string), + .map(ToString::to_string), readme: record .get(12) - .map(std::string::ToString::to_string), + .map(ToString::to_string), repository: record .get(13) - .map(std::string::ToString::to_string), + .map(ToString::to_string), rustversion: record .get(14) - .map(std::string::ToString::to_string), + .map(ToString::to_string), version: record .get(15) - .map(std::string::ToString::to_string), + .map(ToString::to_string), website: record .get(16) - .map(std::string::ToString::to_string), + .map(ToString::to_string), }; // println!("Params: {:?}", params); generate_files(params)?; @@ -600,7 +598,7 @@ pub fn generate_from_csv(csv_path: &str) -> io::Result<()> { /// - If the JSON data cannot be deserialized into the `FileGenerationParams` struct. /// - If there is an error in generating files based on the parameters. /// -pub fn generate_from_json(path: &str) -> std::io::Result<()> { +pub fn generate_from_json(path: &str) -> io::Result<()> { let contents = fs::read_to_string(path)?; let params: FileGenerationParams = serde_json::from_str(&contents)?; generate_files(params)?; @@ -638,11 +636,11 @@ pub fn generate_from_json(path: &str) -> std::io::Result<()> { /// - If the YAML data cannot be deserialized into the `FileGenerationParams` struct. /// - If there is an error in generating files based on the parameters. /// -pub fn generate_from_yaml(path: &str) -> std::io::Result<()> { +pub fn generate_from_yaml(path: &str) -> io::Result<()> { let contents = fs::read_to_string(path)?; let params: FileGenerationParams = serde_yaml::from_str(&contents) .map_err(|e| { - std::io::Error::new(std::io::ErrorKind::Other, e) + io::Error::new(io::ErrorKind::Other, e) })?; generate_files(params)?; Ok(()) @@ -679,11 +677,11 @@ pub fn generate_from_yaml(path: &str) -> std::io::Result<()> { /// - If the TOML data cannot be deserialized into the `FileGenerationParams` struct. /// - If there is an error in generating files based on the parameters. /// -pub fn generate_from_toml(path: &str) -> std::io::Result<()> { +pub fn generate_from_toml(path: &str) -> io::Result<()> { let contents = fs::read_to_string(path)?; let params: FileGenerationParams = toml::from_str(&contents) .map_err(|e| { - std::io::Error::new(std::io::ErrorKind::Other, e) + io::Error::new(io::ErrorKind::Other, e) })?; generate_files(params)?; Ok(()) @@ -717,7 +715,7 @@ pub fn generate_from_toml(path: &str) -> std::io::Result<()> { /// - If an invalid argument is provided. Each argument must be in the form `--name=value`. /// - If there is an error in generating files based on the parameters derived from the arguments. /// -pub fn generate_from_args(args_str: &str) -> std::io::Result<()> { +pub fn generate_from_args(args_str: &str) -> io::Result<()> { let args = args_str.split_whitespace(); let mut params = FileGenerationParams::default(); for arg in args { @@ -753,8 +751,8 @@ pub fn generate_from_args(args_str: &str) -> std::io::Result<()> { "--version" => params.version = Some(value.to_string()), "--website" => params.website = Some(value.to_string()), _ => { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, + return Err(io::Error::new( + io::ErrorKind::Other, format!("Invalid argument: {name}"), )) }