From c2dfd0eb03fd2aac388f8cdbdaf127dda3eba6df Mon Sep 17 00:00:00 2001 From: Greg Chapple Date: Wed, 24 Jun 2015 16:42:00 +0100 Subject: [PATCH 1/3] Implement cargo project templates Project templates allow users to define custom templates which can be used to scaffold projects. These templates consists of a directory of files, each of which will be treated as a mustache template. Example: cargo new myproject --template=http://github.com/someone/nickel-template This would download the template called 'nickel-template' to ~/.cargo/templates/nickel-template. Each file in that directory would then be compiled and rendered to the new project directory created by cargo. Once the template is downloaded, future uses can just reference it by name: cargo new webapp --template nickel-template Certain files will be ignored in template directories. These are namely files which mustache will not be able to compile. Image files, for example are all ignored. Closes issue #396 --- Cargo.lock | 10 ++ Cargo.toml | 1 + src/bin/new.rs | 21 +-- src/cargo/lib.rs | 1 + src/cargo/ops/cargo_new.rs | 227 ++++++++++++++++++++++++++++++--- src/cargo/sources/git/utils.rs | 4 +- src/cargo/util/config.rs | 4 + src/doc/guide.md | 62 +++++++++ src/etc/_cargo | 7 +- src/etc/cargo.bashcomp.sh | 2 +- 10 files changed, 302 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a0a9a44a9d..2aa2cbe390a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,7 @@ dependencies = [ "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libgit2-sys 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mustache 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "registry 0.1.0", @@ -218,6 +219,15 @@ dependencies = [ "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mustache" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num_cpus" version = "0.2.6" diff --git a/Cargo.toml b/Cargo.toml index 65da37271b4..787ccdfe69b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ time = "0.1" toml = "0.1" url = "0.2" winapi = "0.1" +mustache = "0.6.1" [dev-dependencies] tempdir = "0.3" diff --git a/src/bin/new.rs b/src/bin/new.rs index fdfb0283e0c..552763eaebd 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -9,6 +9,7 @@ struct Options { flag_bin: bool, arg_path: String, flag_name: Option, + flag_template: Option, flag_vcs: Option, } @@ -20,31 +21,31 @@ Usage: cargo new -h | --help Options: - -h, --help Print this message - --vcs Initialize a new repository for the given version - control system (git or hg) or do not initialize any version - control at all (none) overriding a global configuration. - --bin Use a binary instead of a library template - --name Set the resulting package name - -v, --verbose Use verbose output + -h, --help Print this message + --vcs Initialize a new repository for the given version + control system (git or hg) or do not initialize any version + control at all (none) overriding a global configuration. + --bin Use a binary instead of a library template + --name Set the resulting package name + --template