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

Resubmission of templating PR (#1747) #3004

Merged
merged 3 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Cargo templating for new and init
PR #3004 This is a resubmission of the PR #1747 (from scratch) which adds
support for templating in Cargo. The templates are implemented using the
handlebars crate (where the original PR used mustache).

Examples:
cargo new --template https://url/to/template somedir foo
cargo new --template https://url/to/templates --template-subdir somedir foo
cargo new --template ../path/to/template somedir foo
  • Loading branch information
Ewan Higgs authored and ehiggs committed Jan 31, 2017
commit 875a8aba7916b63c3c8464008a271f6082e23779
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ fs2 = "0.3"
git2 = "0.6"
git2-curl = "0.7"
glob = "0.2"
handlebars = "0.20"
libc = "0.2"
libgit2-sys = "0.6"
log = "0.3"
miow = "0.1"
num_cpus = "1.0"
regex = "0.1"
rustc-serialize = "0.3"
Expand Down
16 changes: 14 additions & 2 deletions src/bin/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct Options {
flag_lib: bool,
arg_path: Option<String>,
flag_name: Option<String>,
flag_template_subdir: Option<String>,
flag_template: Option<String>,
flag_vcs: Option<ops::VersionControl>,
flag_frozen: bool,
flag_locked: bool,
Expand All @@ -32,6 +34,8 @@ Options:
--bin Use a binary (application) template
--lib Use a library template
--name NAME Set the resulting package name
--template <repository> Use a specified template repository
--template-subdir <template> Use a specified template within a template repository
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
Expand All @@ -47,14 +51,22 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
options.flag_frozen,
options.flag_locked)?;

let Options { flag_bin, flag_lib, arg_path, flag_name, flag_vcs, .. } = options;
let Options {
flag_bin, flag_lib,
arg_path, flag_name,
flag_vcs,
flag_template_subdir, flag_template,
..
} = options;

let tmp = &arg_path.unwrap_or(format!("."));
let opts = ops::NewOptions::new(flag_vcs,
flag_bin,
flag_lib,
tmp,
flag_name.as_ref().map(|s| s.as_ref()));
flag_name.as_ref().map(|s| s.as_ref()),
flag_template_subdir.as_ref().map(|s| s.as_ref()),
flag_template.as_ref().map(|s| s.as_ref()));

let opts_lib = opts.lib;
ops::init(opts, config)?;
Expand Down
16 changes: 14 additions & 2 deletions src/bin/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ pub struct Options {
flag_lib: bool,
arg_path: String,
flag_name: Option<String>,
flag_template_subdir: Option<String>,
flag_template: Option<String>,
flag_vcs: Option<ops::VersionControl>,
flag_frozen: bool,
flag_locked: bool,
Expand All @@ -32,6 +34,8 @@ Options:
--bin Use a binary (application) template
--lib Use a library template
--name NAME Set the resulting package name, defaults to the value of <path>
--template <repository> Use a specified template repository
--template-subdir <template-subdir> Use a specified template within a template repository
-v, --verbose ... Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
Expand All @@ -47,13 +51,21 @@ pub fn execute(options: Options, config: &Config) -> CliResult {
options.flag_frozen,
options.flag_locked)?;

let Options { flag_bin, flag_lib, arg_path, flag_name, flag_vcs, .. } = options;
let Options {
flag_bin, flag_lib,
arg_path, flag_name,
flag_vcs,
flag_template_subdir, flag_template,
..
} = options;

let opts = ops::NewOptions::new(flag_vcs,
flag_bin,
flag_lib,
&arg_path,
flag_name.as_ref().map(|s| s.as_ref()));
flag_name.as_ref().map(|s| s.as_ref()),
flag_template_subdir.as_ref().map(|s| s.as_ref()),
flag_template.as_ref().map(|s| s.as_ref()));

let opts_lib = opts.lib;
ops::new(opts, config)?;
Expand Down
1 change: 1 addition & 0 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern crate flate2;
extern crate fs2;
extern crate git2;
extern crate glob;
extern crate handlebars;
extern crate libc;
extern crate libgit2_sys;
extern crate num_cpus;
Expand Down
Loading