Closed gchp closed 7 years ago
I think that use cases like "generate a new nickel project" belong in a nickel
binary, not as a Cargo extension. Note how your Django example is part of Django, not part of virtualenv.
@steveklabnik I agree, I don't think cargo should care about nickel or any other project for that matter. What I'm suggesting is more the functionality to take a project template and scaffold a project based on that. It would allow for the creation of more than the simple lib or bin setup available currently.
The templates would be external, and maintained by a 3rd party. So the reponsibility of maintaining the templates would be on whoever developed them in the first place.
Fair point on the Django example.
Leiningen, the Clojure equivalent of Cargo, does something much like this: https://github.com/technomancy/leiningen/blob/stable/doc/TEMPLATES.md
The cargo-new
command could definitely be souped up, and this seems like a great idea! A similar improvement would be implementing cargo new
for a pre-existing directory.
Its been a while since I looked at this originally. Getting back into it today and wondering, what do you think of using rust-mustache for these templates?
It would mean that the command would download the template files, compile each one as a mustache template then write them out to the target directory. If not rust-mustache, is there a different preferred template system that would be ok to use here?
I think it looks great so far, however from a interface viewpoint I would like to see 2 additions: 1) a centralized list with published templates, like crates.io for libraries and only using git/http sources as a fallback 2) a manifest.toml for each template with useful data such as template description, used mustache variables etc
So it isn't super extensive right now, but I have a cargo subcommand here: https://github.com/pwoolcoc/cargo-template that does something like this. Currently "templates" are really just existing cargo projects, and I fill in the name
and authors
section of the Cargo.toml
after copying the rest of the files in the project over (minus obvious unnecessary stuff like .git/
and target/
. I also have an index that points to existing templates: https://github.com/rusttemplates/templates . I only have a couple so far, but would love to have more added!
@pwoolcoc oh awesome! You may also be interested in https://github.com/rust-lang/cargo/pull/3004 which is adding a similar-ish feature to cargo new
@alexcrichton yea thanks, I was told about that PR after I posted my project to /r/rust. I guess my github-search-fu wasn't good enough. I'm excited for #3004 to land!
I think this can be closed now.
I'm wondering what you think of extending the
cargo new
command to allow users to specify a template which will be used to scaffold the project.For example:
Where
nickel-rs-template
is a repository containing a sample nickel.rs app with some placeholder values which would get replaced when being generated.An advantage of this is that 3rd party developers could create and maintain templates for working for their project. For instance the example I've listed above could allow developers to quickly generate a "hello world" nickel.rs web application.
The idea behind this is similar to that seen in Django:
django-admin.py startproject --template=xxx
.I'd be happy to work on this, but wanted to see if it's something that may be useful and get any feedback / thoughts on it before beginning.