Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.19 #26

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
["package"]
name = "amble"
description = "First class, scalable rust project generator with batteries included."
version = "0.1.18"
version = "0.1.19"
edition = "2021"
license = "MIT"
authors = ["refcell"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Options:
-b, --bin Builds a cargo binary project
-l, --lib Builds a cargo library project
--full Full generates a full project structure including license, ci, gitignore, etc
--etc Adds an `etc/` directory to the project. This _Et Cetera_ directory is used for storing miscellaneous files
--license Adds an MIT License to the project. The MIT License type can be overridden with the `--with-license` flag
--gitignore Adds a Gitignore file to the project
-d, --description <DESCRIPTION> Specifies the description of the project in the top-level `Cargo.toml` workspace
Expand Down
11 changes: 11 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub struct Args {
#[arg(long)]
full: bool,

/// Adds an `etc/` directory to the project.
/// This _Et Cetera_ directory is used for storing miscellaneous files.
#[arg(long)]
etc: bool,

/// Adds an MIT License to the project.
/// The MIT License type can be overridden with the `--with-license` flag.
#[arg(long)]
Expand Down Expand Up @@ -107,13 +112,15 @@ pub fn run() -> Result<()> {
description,
list,
dependencies,
mut etc,
} = Args::parse();
let project_dir_path = std::path::Path::new(&project_dir);

if full {
with_ci = true;
license = true;
gitignore = true;
etc = true;
}

if list {
Expand Down Expand Up @@ -164,6 +171,10 @@ pub fn run() -> Result<()> {
crate::gitignore::create(project_dir_path, dry_run, Some(&mut builder))?;
}

if etc {
crate::etc::create(project_dir_path, dry_run, Some(&mut builder))?;
}

if !bin && !lib {
crate::root::create(
project_dir_path,
Expand Down
33 changes: 33 additions & 0 deletions src/etc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use eyre::Result;
use ptree::TreeBuilder;
use std::path::Path;
use tracing::instrument;

/// Creates a new etc directory in the given directory.
#[instrument(name = "etc", skip(dir, dry, tree))]
pub(crate) fn create(dir: &Path, dry: bool, tree: Option<&mut TreeBuilder>) -> Result<()> {
tracing::info!("Creating etc directory");
crate::utils::create_dir_gracefully!(dir.join("etc"), dry);
tree.map(|t| t.add_empty_child("etc".to_string()));
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;

#[test]
fn test_create_gitignore() {
let dir = tempdir().unwrap();
let dir_path_buf = dir.path().to_path_buf();
let package_dir = dir_path_buf.join("example");
create(&package_dir, false, None).unwrap();

assert!(package_dir.exists());
assert!(package_dir.join("etc").exists());

// Check that the etc directory is an empty directory
assert!(package_dir.join("etc").read_dir().unwrap().next().is_none());
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod cli;
pub(crate) mod bins;
pub(crate) mod cargo;
pub(crate) mod ci;
pub(crate) mod etc;
pub(crate) mod gitignore;
pub(crate) mod libs;
pub(crate) mod license;
Expand Down
13 changes: 13 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ use eyre::Result;
use inquire::Confirm;
use tracing::instrument;

/// Creates a directory if it doesn't exist and the provided `dry_run` flag is not set.
#[macro_export]
macro_rules! create_dir_gracefully {
($dir:expr, $dry_run:expr) => {
if !$dry_run {
tracing::debug!("Creating directory {:?}", $dir);
std::fs::create_dir_all($dir)?;
}
};
}

pub(crate) use create_dir_gracefully;

/// Checks if rust artifacts are present in the given directory.
/// If `dry_run` is enabled, this method will not error if rust
/// artifacts are found.
Expand Down
Loading