libmake/lib.rs
1// Copyright notice and licensing information.
2// These lines indicate the copyright of the software and its licensing terms.
3// SPDX-License-Identifier: Apache-2.0 OR MIT indicates dual licensing under Apache 2.0 or MIT licenses.
4// Copyright © 2023-2024 LibMake. All rights reserved.
5
6//! # `LibMake`
7//!
8//! A code generator to reduce repetitive tasks and build high-quality Rust libraries.
9//!
10//! *Part of the [Mini Functions][0] family of libraries.*
11//!
12//! [](https://libmake.com)
13//!
14//! <center>
15//!
16//! [](https://www.rust-lang.org)
17//! [](https://crates.io/crates/libmake)
18//! [](https://lib.rs/crates/libmake)
19//! [](https://github.com/sebastienrousseau/libmake)
20//! [](http://opensource.org/licenses/MIT)
21//!
22//! </center>
23//!
24//! ## Overview
25//!
26//! `LibMake` is a tool designed to quickly help create high-quality
27//! Rust libraries by generating a set of pre-filled and pre-defined
28//! templated files. This opinionated boilerplate scaffolding tool aims
29//! to greatly reduce development time and minimize repetitive tasks,
30//! allowing you to focus on your business logic while enforcing
31//! standards, best practices, consistency, and providing style guides
32//! for your library.
33//!
34//! With `LibMake`, you can easily generate a new Rust library code base
35//! structure with all the necessary files, layouts, build
36//! configurations, code, tests, benchmarks, documentation, and much
37//! more in a matter of seconds.
38//!
39//! The library is designed to be used as a command-line tool. It is
40//! available on [Crates.io](https://crates.io/crates/libmake) and
41//! [Lib.rs](https://lib.rs/crates/libmake).
42//!
43//! ## Features
44//!
45//! `LibMake` offers the following features and benefits:
46//!
47//! - Create your Rust library with ease using the command-line
48//! interface or by providing a configuration file in CSV, JSON, or
49//! YAML format.
50//! - Rapidly generate new library projects with a pre-defined structure
51//! and boilerplate code that you can customize with your own template.
52//! - Automatically generate basic functions, methods, and macros to get
53//! you started with your Rust library.
54//! - Enforce best practices and standards with starter documentation,
55//! test suites, and benchmark suites that are designed to help you
56//! get up and running quickly.
57//!
58//! ## Usage
59//!
60//! - [`serde`][]: Enable serialization/deserialization via serde
61//!
62//! [`serde`]: https://github.com/serde-rs/serde
63//! [0]: https://minifunctions.com/libmake "Mini Functions"
64//!
65#![allow(clippy::must_use_candidate)]
66#![cfg_attr(feature = "bench", feature(test))]
67#![deny(dead_code)]
68#![deny(rustc::existing_doc_keyword)]
69#![doc(
70 html_favicon_url = "https://kura.pro/libmake/images/favicon.ico",
71 html_logo_url = "https://kura.pro/libmake/images/logos/libmake.svg",
72 html_root_url = "https://docs.rs/libmake"
73)]
74#![forbid(missing_debug_implementations)]
75#![forbid(missing_docs)]
76#![forbid(unreachable_pub)]
77#![forbid(unsafe_code)]
78#![crate_name = "libmake"]
79#![crate_type = "lib"]
80
81// Import necessary dependencies
82use crate::args::process_arguments;
83use crate::cli::build;
84use crate::utilities::uuid::generate_unique_string;
85use dtt::DateTime;
86use rlg::{log_format::LogFormat, log_level::LogLevel, macro_log};
87use std::{error::Error, fs::File, io::Write};
88
89/// The `args` module contains functions for processing command-line
90/// arguments.
91pub mod args;
92/// The `cli` module contains functions for processing command-line
93/// input.
94pub mod cli;
95/// The `generator` module contains functions for generating the new
96/// library.
97pub mod generator;
98/// The `generators` module contains functions for generating code.
99pub mod generators;
100/// The `interface` module contains functions for displaying the
101/// interface.
102pub mod interface;
103/// The `macros` module contains functions for generating macros.
104pub mod macros;
105/// The `models` module contains the models for the library.
106pub mod models;
107/// The `utils` module contains a function for reading a CSV file at the
108/// given file path and returns the value of the given field.
109pub mod utils;
110
111/// The `utilities` module contains utility functions for the library.
112pub mod utilities;
113
114/// Initializes the logger with a file logger and a terminal logger and processes
115/// command-line arguments to generate the new library.
116///
117/// # Errors
118///
119/// This function will return an error in the following situations:
120///
121/// - If there is a problem generating ASCII art for the tool's CLI.
122/// - If an error occurs while building the command-line interface or processing arguments.
123/// - Any other errors that may arise from operations performed within the function.
124///
125pub fn run() -> Result<(), Box<dyn Error>> {
126 let date = DateTime::new();
127 let iso = date.iso_8601;
128
129 // Open the log file for appending
130 let mut log_file = File::create("./libmake.log")?;
131
132 // Generate ASCII art for the tool's CLI
133 let log = macro_log!(
134 &generate_unique_string(),
135 &iso,
136 &LogLevel::INFO,
137 "deps",
138 "ASCII art generation event started.",
139 &LogFormat::CLF
140 );
141 // Write the log to both the console and the file
142 writeln!(log_file, "{}", log)?;
143
144 // Printing the ASCII art to the console
145 println!("{}", macro_ascii!("LibMake"));
146
147 let log = macro_log!(
148 &generate_unique_string(),
149 &iso,
150 &LogLevel::INFO,
151 "deps",
152 "ASCII art generation event completed.",
153 &LogFormat::CLF
154 );
155 // Write the log to both the console and the file
156 writeln!(log_file, "{}", log)?;
157
158 // Build the command-line interface and process the arguments
159 let matches = build()?;
160 process_arguments(&matches)?;
161
162 // Check the number of arguments, provide a welcome message if no arguments were passed
163 macro_log!(
164 &generate_unique_string(),
165 &iso,
166 &LogLevel::INFO,
167 "cli",
168 "Welcome to LibMake! 👋\n\nLet's get started! Please, run `libmake --help` for more information.",
169 &LogFormat::CLF
170 );
171 eprintln!(
172 "\n\nWelcome to LibMake! 👋\n\nLet's get started! Please, run `libmake --help` for more information.\n"
173 );
174
175 Ok(())
176}