From 909b7a5d5fe6a36c3b3217265968b55daf79301a Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Sun, 22 Mar 2020 15:49:41 -0700 Subject: [PATCH 1/2] feat: create README for cargo new bin crates --- src/cargo/ops/cargo_new.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index f9811f7a690..714a0d7594e 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -716,6 +716,22 @@ edition = {} .as_bytes(), )?; + // Create README for binary crates + // Eventually, we will do something similar for library and workspace crates + + if opts.bin { + paths::write( + &path.join("README.md"), + format!( + r#"TODO: add a description of this crate's purpose + cargo install [{}] + "#, + name, + ) + .as_bytes(), + )?; + } + // Create all specified source files (with respective parent directories) if they don't exist. for i in &opts.source_files { From fb78109688c1088251bec3a5acb8fe2b34f36815 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Sun, 22 Mar 2020 15:50:01 -0700 Subject: [PATCH 2/2] feat: add tests to check for README cargo new fix: update --- src/cargo/ops/cargo_new.rs | 2 +- tests/testsuite/new.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 714a0d7594e..d6a368170f7 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -724,7 +724,7 @@ edition = {} &path.join("README.md"), format!( r#"TODO: add a description of this crate's purpose - cargo install [{}] +cargo install [{}] "#, name, ) diff --git a/tests/testsuite/new.rs b/tests/testsuite/new.rs index 7455094d688..27406660d73 100644 --- a/tests/testsuite/new.rs +++ b/tests/testsuite/new.rs @@ -25,6 +25,7 @@ fn simple_lib() { assert!(paths::root().join("foo/Cargo.toml").is_file()); assert!(paths::root().join("foo/src/lib.rs").is_file()); assert!(!paths::root().join("foo/.gitignore").is_file()); + assert!(!paths::root().join("foo/README.md").is_file()); let lib = paths::root().join("foo/src/lib.rs"); let mut contents = String::new(); @@ -57,6 +58,7 @@ fn simple_bin() { assert!(paths::root().join("foo").is_dir()); assert!(paths::root().join("foo/Cargo.toml").is_file()); assert!(paths::root().join("foo/src/main.rs").is_file()); + assert!(paths::root().join("foo/README.md").is_file()); cargo_process("build").cwd(&paths::root().join("foo")).run(); assert!(paths::root() @@ -84,6 +86,7 @@ fn simple_git() { assert!(paths::root().join("foo/src/lib.rs").is_file()); assert!(paths::root().join("foo/.git").is_dir()); assert!(paths::root().join("foo/.gitignore").is_file()); + assert!(!paths::root().join("foo/README.md").is_file()); let fp = paths::root().join("foo/.gitignore"); let mut contents = String::new();