Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot committed Nov 13, 2024
1 parent 01fd0ec commit 62a36bb
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 276 deletions.
11 changes: 6 additions & 5 deletions loco-new/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use duct::cmd;
use loco::{
generator::{executer, extract_default_template, Generator},
settings::Settings,
wizard, wizard_opts, Result,
wizard, Result,
};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;
Expand Down Expand Up @@ -41,22 +41,23 @@ enum Commands {

/// DB Provider
#[arg(long)]
db: Option<wizard_opts::DBOption>,
db: Option<wizard::DBOption>,

/// Background worker configuration
#[arg(long)]
bg: Option<wizard_opts::BackgroundOption>,
bg: Option<wizard::BackgroundOption>,

/// Assets serving configuration
#[arg(long)]
assets: Option<wizard_opts::AssetsOption>,
assets: Option<wizard::AssetsOption>,

/// Allows create loco starter in target git repository
#[arg(short, long)]
allow_in_git_repo: bool,
},
}

#[allow(clippy::cognitive_complexity)]
fn main() -> Result<()> {
let cli = Cli::parse();
tracing_subscriber::fmt()
Expand Down Expand Up @@ -94,7 +95,7 @@ fn main() -> Result<()> {
tracing::debug!(dir = %to.display(), "creating application directory");
std::fs::create_dir_all(&to)?;

let args = wizard_opts::ArgsPlaceholder { db, bg, assets };
let args = wizard::ArgsPlaceholder { db, bg, assets };
let user_selection = wizard::start(&args)?;

let generator_tmp_folder = extract_default_template()?;
Expand Down
1 change: 1 addition & 0 deletions loco-new/src/generator/executer/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl Executer for FileSystem {
self.render_and_rename_template_file(&copied_path, settings)
}

#[allow(clippy::cognitive_complexity)]
fn copy_template_dir(&self, directory_path: &Path, settings: &Settings) -> super::Result<()> {
let source_path = self.source_dir.join(directory_path);
let target_path = self.target_dir.join(directory_path);
Expand Down
5 changes: 1 addition & 4 deletions loco-new/src/generator/executer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
//! This module defines error handling and the [`Executer`] trait for file and
//! template operations within the application. It includes custom error types
//! for handling different failure scenarios, including file system and template
//! processing errors.
//! This module defines error handling and the [`Executer`] trait
use crate::settings::Settings;
mod filesystem;
Expand Down
9 changes: 6 additions & 3 deletions loco-new/src/generator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! This module defines the `Generator` struct, which is responsible for
//! executing scripted commands for file and template operations. It integrates
//! with an executor to perform file manipulations and uses a scripting engine
//! to run custom scripts based on application settings.
//! executing scripted commands
use std::path::{Path, PathBuf};
pub mod executer;
Expand Down Expand Up @@ -112,6 +110,11 @@ impl Generator {
Ok(())
}

/// Creates a single file in the specified path.
///
/// # Errors
///
/// Returns an error if the file copy operation fails.
pub fn create_file(
&mut self,
path: &str,
Expand Down
13 changes: 7 additions & 6 deletions loco-new/src/generator/template.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! This module defines a `Template` struct for handling template files.
//! It includes methods to identify template files, render templates
//! with injected settings, and modify file paths by stripping specific extensions.
use crate::settings::Settings;
use rand::{distributions::Alphanumeric, rngs::StdRng, Rng, SeedableRng};
use std::sync::{Arc, Mutex};
use std::{
collections::HashMap,
path::{Path, PathBuf},
sync::{Arc, Mutex},
};

use rand::{distributions::Alphanumeric, rngs::StdRng, Rng, SeedableRng};
use tera::{Context, Tera};

use crate::settings::Settings;

const TEMPLATE_EXTENSION: &str = "t";

fn generate_random_string<R: Rng>(rng: &mut R, length: u64) -> String {
Expand Down Expand Up @@ -44,7 +44,8 @@ impl Template {
rng: Arc::new(Mutex::new(rng)),
}
}
/// Checks if the provided file path has a ".t" extension, marking it as a template.
/// Checks if the provided file path has a ".t" extension, marking it as a
/// template.
///
/// Returns `true` if the file has a ".t" extension, otherwise `false`.
#[must_use]
Expand Down
1 change: 0 additions & 1 deletion loco-new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod generator;
pub mod settings;
pub mod wizard;
pub mod wizard_opts;

pub type Result<T> = std::result::Result<T, Error>;

Expand Down
30 changes: 17 additions & 13 deletions loco-new/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use heck::ToSnakeCase;
use rhai::{CustomType, TypeBuilder};
use serde::{Deserialize, Serialize};

use crate::{wizard, wizard_opts, LOCO_VERSION};
use crate::{
wizard::{self, AssetsOption, BackgroundOption, DBOption},
LOCO_VERSION,
};

/// Represents general application settings.
#[derive(Serialize, Deserialize, Clone, Debug, CustomType)]
Expand All @@ -24,10 +27,10 @@ pub struct Settings {
pub loco_version_text: String,
}

impl From<wizard_opts::DBOption> for Option<Db> {
fn from(db_option: wizard_opts::DBOption) -> Self {
impl From<DBOption> for Option<Db> {
fn from(db_option: DBOption) -> Self {
match db_option {
wizard_opts::DBOption::None => None,
DBOption::None => None,
_ => Some(Db {
kind: db_option.clone(),
endpoint: db_option.endpoint_config().to_string(),
Expand All @@ -36,19 +39,19 @@ impl From<wizard_opts::DBOption> for Option<Db> {
}
}

impl From<wizard_opts::BackgroundOption> for Option<Background> {
fn from(bg: wizard_opts::BackgroundOption) -> Self {
impl From<BackgroundOption> for Option<Background> {
fn from(bg: BackgroundOption) -> Self {
match bg {
wizard_opts::BackgroundOption::None => None,
BackgroundOption::None => None,
_ => Some(Background { kind: bg }),
}
}
}

impl From<wizard_opts::AssetsOption> for Option<Asset> {
fn from(asset: wizard_opts::AssetsOption) -> Self {
impl From<AssetsOption> for Option<Asset> {
fn from(asset: AssetsOption) -> Self {
match asset {
wizard_opts::AssetsOption::None => None,
AssetsOption::None => None,
_ => Some(Asset { kind: asset }),
}
}
Expand Down Expand Up @@ -89,6 +92,7 @@ impl Settings {
}
impl Default for Settings {
fn default() -> Self {
#[allow(clippy::default_trait_access)]
Self {
package_name: Default::default(),
module_name: Default::default(),
Expand Down Expand Up @@ -118,20 +122,20 @@ fn get_loco_version_text() -> String {
/// Database configuration settings.
#[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)]
pub struct Db {
pub kind: wizard_opts::DBOption,
pub kind: DBOption,
pub endpoint: String,
}

/// Background processing configuration.
#[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)]
pub struct Background {
pub kind: wizard_opts::BackgroundOption,
pub kind: BackgroundOption,
}

/// Asset configuration settings.
#[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)]
pub struct Asset {
pub kind: wizard_opts::AssetsOption,
pub kind: AssetsOption,
}

#[derive(Serialize, Deserialize, Clone, Debug, Default, CustomType)]
Expand Down
Loading

0 comments on commit 62a36bb

Please sign in to comment.