From f201a7b67030b05033ebdd936851ef9d66106d7e Mon Sep 17 00:00:00 2001 From: Sebastien Rousseau Date: Sun, 10 Nov 2024 16:35:40 +0000 Subject: [PATCH] refactor(ssg): :art: refactoring structure and simplifying overall code --- src/{cmd => }/cli.rs | 12 +++++------- src/cmd/mod.rs | 35 ----------------------------------- src/lib.rs | 11 ++++++++--- src/{cmd => }/process.rs | 4 ++-- 4 files changed, 15 insertions(+), 47 deletions(-) rename src/{cmd => }/cli.rs (98%) delete mode 100644 src/cmd/mod.rs rename src/{cmd => }/process.rs (99%) diff --git a/src/cmd/cli.rs b/src/cli.rs similarity index 98% rename from src/cmd/cli.rs rename to src/cli.rs index 6671d23e..5400de9a 100644 --- a/src/cmd/cli.rs +++ b/src/cli.rs @@ -3,9 +3,7 @@ //! # Command Line Interface Module //! -//! This module provides a secure and robust command-line interface for the Shokunin -//! Static Site Generator. It handles argument parsing, configuration management, -//! and validation of user inputs. +//! This module provides a secure and robust command-line interface for the Shokunin Static Site Generator. It handles argument parsing, configuration management, and validation of user inputs. //! //! ## Key Features //! @@ -18,8 +16,8 @@ //! //! ## Example Usage //! ```rust,no_run -//! use ssg::cmd::cli::build; -//! use ssg::cmd::cli::ShokuninConfig; +//! use ssg::cli::build; +//! use ssg::cli::ShokuninConfig; //! //! fn main() -> anyhow::Result<()> { //! // Initialize the CLI with arguments from `build()` @@ -85,7 +83,7 @@ pub enum CliError { /// # Example /// /// ```rust,no_run -/// use ssg::cmd::cli::ShokuninConfig; +/// use ssg::cli::ShokuninConfig; /// use std::path::PathBuf; /// /// let config = ShokuninConfig { @@ -154,7 +152,7 @@ impl ShokuninConfig { /// # Example /// /// ```rust,no_run - /// use ssg::cmd::cli::{build, ShokuninConfig}; + /// use ssg::cli::{build, ShokuninConfig}; /// /// let matches = build().get_matches(); /// let config = ShokuninConfig::from_matches(&matches).unwrap(); diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs deleted file mode 100644 index 0f63979d..00000000 --- a/src/cmd/mod.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright © 2024 Shokunin Static Site Generator. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 OR MIT - -//! # Shokunin Static Site Generator Modules -//! -//! This module exposes key submodules of the Shokunin Static Site Generator. -//! -//! ## Module Overview -//! -//! - [`cli`]: Contains functions and structures for handling command-line interface (CLI) input, argument parsing, and configuration management. -//! - [`process`]: Manages argument validation, error handling, and any required processing steps based on user inputs. -//! - -/// The `cli` module provides functions and structures to manage the command-line interface (CLI) of the Shokunin Static Site Generator. -/// -/// This module utilises the `clap` crate to define and parse command-line arguments, offering secure handling of paths, options, and configuration for the generator's functionality. -/// -/// ## Features -/// - **Argument Parsing**: Handles various command-line arguments for customising the site generation process. -/// - **Configuration Management**: Validates and manages user configurations, ensuring all required options are set. -/// - **Secure Path Handling**: Ensures that paths provided by users are safe and valid. -/// -pub mod cli; - -/// The `process` module contains functions for processing command-line arguments and executing actions accordingly. -/// -/// This module handles various tasks such as validating user-provided arguments and performing actions like initialising directories or triggering the static site generation based on the received input. -/// -/// ## Features -/// -/// - **Argument Validation**: Verifies that required arguments are present and in valid formats. -/// - **Error Handling**: Provides custom errors for missing arguments, directory creation issues, and other potential problems. -/// - **Execution Flow**: Facilitates the primary actions of the static site generator based on parsed command-line arguments. -/// -pub mod process; diff --git a/src/lib.rs b/src/lib.rs index c832d37f..c5b30c78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,12 @@ use staticdatagen::{ }; /// Module declarations -pub mod cmd; + +/// Process module for handling site generation +pub mod process; + +/// CLI module for command-line interface +pub mod cli; /// Re-exports pub use staticdatagen; @@ -130,11 +135,11 @@ pub fn run() -> Result<()> { .context("Failed to create log file")?; // Display banner and log initialization - cmd::cli::print_banner(); + cli::print_banner(); log_initialization(&mut log_file, &date)?; // Parse command-line arguments - let matches = cmd::cli::build().get_matches(); + let matches = cli::build().get_matches(); log_arguments(&mut log_file, &date)?; // Extract and validate paths diff --git a/src/cmd/process.rs b/src/process.rs similarity index 99% rename from src/cmd/process.rs rename to src/process.rs index b4d3f157..38167ee8 100644 --- a/src/cmd/process.rs +++ b/src/process.rs @@ -60,7 +60,7 @@ pub enum ProcessError { /// /// ```rust,no_run /// # use clap::{ArgMatches, Command}; -/// # use ssg::cmd::process::get_argument; +/// # use ssg::process::get_argument; /// let matches = Command::new("test") /// .arg(clap::arg!(--"config" "Specifies the configuration file")) /// .get_matches_from(vec!["test", "--config", "path/to/config.toml"]); @@ -96,7 +96,7 @@ pub fn get_argument( /// /// ```rust,no_run /// # use std::path::Path; -/// # use ssg::cmd::process::ensure_directory; +/// # use ssg::process::ensure_directory; /// let path = Path::new("path/to/output"); /// ensure_directory(path, "output").expect("Failed to ensure directory exists"); /// ```