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

cargo new: create README in bin crates #8029

Closed
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
16 changes: 16 additions & 0 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down