Skip to content

Commit

Permalink
fix(libmake): 🚑 gitignore, and optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Mar 16, 2024
1 parent b3a76bb commit cd9b8d8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.DS_Store
*.profraw
ssg.log
*.log
/.vscode/
/target/
build
Expand Down
2 changes: 0 additions & 2 deletions libmake.log

This file was deleted.

54 changes: 26 additions & 28 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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}"),
))
}
Expand Down

0 comments on commit cd9b8d8

Please sign in to comment.