Skip to content

Commit

Permalink
feat(libmake): ✨ integrating with xtasks
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Dec 31, 2023
1 parent d852f13 commit 41e50b9
Show file tree
Hide file tree
Showing 26 changed files with 494 additions and 451 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[alias]
xtask = "run --package xtask --bin xtask --"
xtask = "run --package xtasks --bin xtasks --"
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ include = [
"/README.md",
"/src/**",
"/tests/**",
"/xtask/**",
]

[workspace]
members = ["xtask"]

[[bench]]
name = "benchmark"
harness = false
Expand All @@ -52,8 +48,10 @@ reqwest = { version = "0.11.23", features = ["blocking"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
serde_yaml = "0.9.29"
tempfile = "3.9.0"
toml = "0.8.8"
vrd = "0.0.5"
xtasks = "0.0.2"

[dev-dependencies]
criterion = "0.5.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,6 @@ providing a lot of useful suggestions on how to improve this project.
[crates-badge]: https://img.shields.io/crates/v/libmake.svg?style=for-the-badge "Crates.io Badge"
[divider]: https://kura.pro/common/images/elements/divider.svg "divider"
[docs-badge]: https://img.shields.io/docsrs/libmake.svg?style=for-the-badge "Docs.rs Badge"
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.2.0-orange.svg?style=for-the-badge "Lib.rs Badge"
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.2.1-orange.svg?style=for-the-badge "Lib.rs Badge"
[license-badge]: https://img.shields.io/crates/l/libmake.svg?style=for-the-badge "License Badge"
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust "Made With Rust Badge"
4 changes: 2 additions & 2 deletions TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
alt="LibMake logo" width="261" align="right" />

<!-- markdownlint-enable MD033 MD041 -->
# LibMake v0.2.0 🦀
# LibMake v0.2.1 🦀

A code generator to reduce repetitive tasks and build high-quality Rust libraries.

Expand Down Expand Up @@ -63,6 +63,6 @@ The library is designed to be used as a command-line tool. It is available on [C
[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/libmake?style=for-the-badge&token=Q9KJ6XXL67 "Codecov Badge"
[crates-badge]: https://img.shields.io/crates/v/libmake.svg?style=for-the-badge "Crates.io Badge"
[docs-badge]: https://img.shields.io/docsrs/libmake.svg?style=for-the-badge "Docs.rs Badge"
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.2.0-orange.svg?style=for-the-badge "Lib.rs Badge"
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.2.1-orange.svg?style=for-the-badge "Lib.rs Badge"
[license-badge]: https://img.shields.io/crates/l/libmake.svg?style=for-the-badge "License Badge"
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust "Made With Rust Badge"
12 changes: 5 additions & 7 deletions examples/generate_from_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,29 @@
// Import the necessary function for generating files from arguments
use libmake::generator::generate_from_args;

fn main() -> std::io::Result<()> {
fn main() {
// Simulate command line arguments
let args = "--author=Me --output=my_library"
.split(' ')
.map(|s| s.to_string())
.map(std::string::ToString::to_string) // Directly using the method
.collect::<Vec<String>>();

// Check if there are at least two arguments (program name and at least one option)
if args.len() < 2 {
eprintln!("Usage: {} <args>", args[0]);
return Ok(());
return;
}

// Join the arguments (excluding the program name) into a single string
let args_str = args[1..].join(" ");

// Call the `generate_from_args` function with the arguments string
let result = generate_from_args(&args_str);
println!("{:?}", result);
println!("{result:?}");

// Check the result of the function call and print a message accordingly
match result {
Ok(()) => println!("Successfully generated files!"),
Err(err) => eprintln!("Error: {}", err),
Err(err) => eprintln!("Error: {err}"),
}

Ok(())
}
4 changes: 2 additions & 2 deletions examples/generate_from_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ fn main() {
// This function generates template files based on the configuration.
match generate_from_config(file_path, file_type) {
// If generation is successful, do nothing (the template files are created).
Ok(_) => (),
Ok(()) => (),
// If there is an error during generation, print an error message.
Err(err) => eprintln!("Error: {}", err),
Err(err) => eprintln!("Error: {err}"),
}
}
2 changes: 1 addition & 1 deletion examples/get_json_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ fn main() {
} else {
String::new()
};
println!("🦀 get_json_field, ✅ {}: {}", field_author, value);
println!("🦀 get_json_field, ✅ {field_author}: {value}");
}
4 changes: 2 additions & 2 deletions examples/get_yaml_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ fn main() {
.split('\n')
.map(|s| s.trim_start_matches("- "))
.filter(|s| !s.is_empty())
.map(|s| format!("\"{}\"", s))
.map(|s| format!("\"{s}\""))
.collect();
format!("[{}]", keywords.join(", "))
} else {
String::new()
};

println!("🦀 get_yaml_field, ✅ {}: {}", field_keywords, value);
println!("🦀 get_yaml_field, ✅ {field_keywords}: {value}");
}
14 changes: 14 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ use std::error::Error;
/// * `matches` - An instance of `clap::ArgMatches` containing the
/// parsed command line arguments.
///
/// # Errors
///
/// This function will return an error in the following situations:
///
/// - If a specified file path for a subcommand (CSV, YAML, JSON, TOML) is invalid or the file cannot be read.
/// - If there is an error in parsing the file contents into the respective file format (CSV, YAML, JSON, TOML).
/// - If there is an error in generating files based on the parameters derived from the command line arguments.
///
/// # Panics
///
/// This function will panic if a required command line argument is not provided.
/// For example, it will panic if the `csv` subcommand is used without specifying
/// a CSV file path.
///
pub fn process_arguments(
matches: &ArgMatches,
) -> Result<(), Box<dyn Error>> {
Expand Down
28 changes: 15 additions & 13 deletions src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,46 @@ use std::fmt;

/// Error type for ASCII art generation failures.
#[derive(Debug)]
pub enum AsciiArtError {
pub enum ArtError {
/// Represents a failure to load the FIGfont.
FontLoadError,
/// Represents a failure to convert text to ASCII art.
ConversionError,
}

impl fmt::Display for AsciiArtError {
impl fmt::Display for ArtError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
AsciiArtError::FontLoadError => {
Self::FontLoadError => {
write!(f, "Failed to load FIGfont")
}
AsciiArtError::ConversionError => {
Self::ConversionError => {
write!(f, "Failed to convert text to ASCII art")
}
}
}
}

impl Error for AsciiArtError {}
impl Error for ArtError {}

/// Generates ASCII art from the given text using the standard FIGfont.
/// Generates ASCII art from the given text using the standard `FIGfont`.
///
/// # Arguments
///
/// * `text` - The text to convert to ASCII art.
///
/// # Returns
/// # Errors
///
/// This function returns a `Result` with the ASCII art as `String` or
/// an `AsciiArtError` if the operation fails.
/// This function returns an `Err` in the following situations:
///
pub fn generate_ascii_art(text: &str) -> Result<String, AsciiArtError> {
let standard_font = FIGfont::standard()
.map_err(|_| AsciiArtError::FontLoadError)?;
/// - If the standard `FIGfont` fails to load (`FontLoadError`).
/// - If the text cannot be converted to ASCII art (`ConversionError`).
///
pub fn generate_ascii_art(text: &str) -> Result<String, ArtError> {
let standard_font =
FIGfont::standard().map_err(|_| ArtError::FontLoadError)?;
let figure = standard_font
.convert(text)
.ok_or(AsciiArtError::ConversionError)?;
.ok_or(ArtError::ConversionError)?;
Ok(figure.to_string())
}
Loading

0 comments on commit 41e50b9

Please sign in to comment.