Skip to content

Commit

Permalink
Merge pull request #50 from refcell/refcell/readme
Browse files Browse the repository at this point in the history
feat(root): Readme Generation
  • Loading branch information
refcell authored Oct 26, 2023
2 parents 6cdab9f + 2a48a14 commit b62df7c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
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.23"
version = "0.1.24"
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 @@ -173,6 +173,7 @@ Options:
-a, --authors <AUTHORS> Override the project authors
-b, --bin Builds a cargo binary project
-l, --lib Builds a cargo library project
--without-readme Prevents a readme from being generated
--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
Expand Down
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ pub struct Args {
#[arg(long, short)]
lib: bool,

/// Prevents a readme from being generated.
#[arg(long)]
without_readme: bool,

/// Full generates a full project structure including license, ci, gitignore, etc.
#[arg(long)]
full: bool,
Expand Down Expand Up @@ -103,6 +107,7 @@ pub fn run() -> Result<()> {
v,
dry_run,
bare,
without_readme,
name,
project_dir,
mut overwrite,
Expand Down Expand Up @@ -187,6 +192,7 @@ pub fn run() -> Result<()> {
&name,
description.as_ref(),
dry_run,
without_readme,
authors,
dependencies,
Some(&mut builder),
Expand Down
23 changes: 19 additions & 4 deletions src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,34 @@ use ptree::TreeBuilder;
use tracing::instrument;

/// Creates new top-level workspace artifacts at the given directory &[Path].
#[allow(clippy::too_many_arguments)]
#[instrument(name = "workspace", skip(dir, name, description, dry, author, tree))]
pub(crate) fn create(
dir: &Path,
name: impl AsRef<str> + std::fmt::Display,
description: Option<impl AsRef<str> + std::fmt::Display>,
dry: bool,
no_readme_override: bool,
author: Option<Vec<String>>,
overrides: Option<Vec<String>>,
tree: Option<&mut TreeBuilder>,
mut tree: Option<&mut TreeBuilder>,
) -> Result<()> {
tracing::info!("Creating top level workspace artifacts for {}", name);

let description = description
.map(|s| s.as_ref().to_string())
.unwrap_or(format!("{} workspace", name));

if !dry && !no_readme_override {
tracing::debug!("Writing {:?}", dir.join("README.md"));
let mut file = std::fs::File::create(dir.join("README.md"))?;
file.write_all(description.as_bytes())?;
tree.as_deref_mut()
.map(|t| t.add_empty_child("README.md".to_string()));
}

if !dry {
tracing::debug!("Writing {:?}", dir.join("Cargo.toml"));
let description = description
.map(|s| s.as_ref().to_string())
.unwrap_or(format!("{} workspace", name));
fill_cargo(
&dir.join("Cargo.toml"),
author,
Expand Down Expand Up @@ -365,13 +376,15 @@ debug = true
"example",
Some("example workspace"),
false,
false,
None,
None,
None,
)
.unwrap();
assert!(dir_path_buf.exists());
assert!(dir_path_buf.join("Cargo.toml").exists());
assert!(dir_path_buf.join("README.md").exists());
}

#[test]
Expand All @@ -383,11 +396,13 @@ debug = true
"example",
Some("example workspace"),
true,
false,
None,
None,
None,
)
.unwrap();
assert!(!dir_path_buf.join("Cargo.toml").exists());
assert!(!dir_path_buf.join("README.md").exists());
}
}

0 comments on commit b62df7c

Please sign in to comment.