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 --example #6939

Closed
Alxandr opened this issue May 14, 2019 · 6 comments
Closed

Cargo new --example #6939

Alxandr opened this issue May 14, 2019 · 6 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-new

Comments

@Alxandr
Copy link

Alxandr commented May 14, 2019

Describe the problem you are trying to solve

Make it easier to add examples to a project.

Describe the solution you'd like

I would like a basic scaffold of an example, probably with just an empty main method when I run cargo new --example <name>.

@Alxandr Alxandr added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label May 14, 2019
@jesselawson
Copy link

So if I were to run cargo new --example celeryman, what would be different code-wise from running cargo new celeryman?

I wonder if you might be referring to scaffolding, and are hoping to get some Yeoman-esque functionality in the cargo tool?

@Alxandr
Copy link
Author

Alxandr commented May 15, 2019 via email

@mbartelsm
Copy link

mbartelsm commented Jul 6, 2020

It would be nice to have this feature.

The command should generate:

  • An examples folder, if one doesn't exist already
  • An examples/{name} subfolder
  • An examples/{name}/main.rs file, potentially with a hello-world program, much like with the standard cargo new command
  • The necessary manifest data within the cargo.toml file of the root project.

@happybeing
Copy link

It would help if the docs for cargo run --example said more than 'Runs the specified example' here. That's just annoying. I got there by searching the web, but so far haven't found an explanation of what it really means and how to create an example.

I can just copy stuff from an [cough] example crate and fiddle until it works, but it would help to have a pointer to an explanation in the docs.

@mbartelsm
Copy link

Yeah, there's also that. The only reason I know about the feature is because I noticed a large-ish project using it and I reverse engineered it. The docs weren't of much help.

@epage
Copy link
Contributor

epage commented Nov 1, 2023

From #3832

As of now, cargo init doesn't really generate many files. I doubt it worth making it additive. That said, when cargo gets cargo-template support (#5151), this might be quite interesting to explore.

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-new
Projects
None yet
Development

No branches or pull requests

7 participants
@ehuss @epage @Alxandr @happybeing @jesselawson @mbartelsm and others