feat: enable versioned templates (#3223)
* feat: enable versioned templates * no subtemplate for 0.6
This commit is contained in:
1 parent
fca5a82e2b
commit
7d353c9f17
2 files changed
+27
-15
No files matched your search
@@ -16,8 +16,8 @@ pub struct Create {
|
|||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
|
||||||
/// Template path
|
/// Template path
|
||||||
#[clap(default_value = DEFAULT_TEMPLATE, short, long)]
|
#[clap(short, long)]
|
||||||
template: String,
|
template: Option<String>,
|
||||||
|
|
||||||
/// Branch to select when using `template` from a git repository.
|
/// Branch to select when using `template` from a git repository.
|
||||||
/// Mutually exclusive with: `--revision`, `--tag`.
|
/// Mutually exclusive with: `--revision`, `--tag`.
|
||||||
@@ -55,6 +55,9 @@ impl Create {
|
|||||||
self.name = Some(create::name_from_path(&self.path)?);
|
self.name = Some(create::name_from_path(&self.path)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no template is specified, use the default one and set the branch to the latest release.
|
||||||
|
resolve_template_and_branch(&mut self.template, &mut self.branch);
|
||||||
|
|
||||||
let args = GenerateArgs {
|
let args = GenerateArgs {
|
||||||
define: self.option,
|
define: self.option,
|
||||||
destination: Some(self.path),
|
destination: Some(self.path),
|
||||||
@@ -67,7 +70,7 @@ impl Create {
|
|||||||
name: self.name,
|
name: self.name,
|
||||||
silent: self.yes,
|
silent: self.yes,
|
||||||
template_path: TemplatePath {
|
template_path: TemplatePath {
|
||||||
auto_path: Some(self.template),
|
auto_path: self.template,
|
||||||
branch: self.branch,
|
branch: self.branch,
|
||||||
revision: self.revision,
|
revision: self.revision,
|
||||||
subfolder: self.subtemplate,
|
subfolder: self.subtemplate,
|
||||||
@@ -83,6 +86,20 @@ impl Create {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If no template is specified, use the default one and set the branch to the latest release.
|
||||||
|
///
|
||||||
|
/// Allows us to version templates under the v0.5/v0.6 scheme on the templates repo.
|
||||||
|
pub(crate) fn resolve_template_and_branch(
|
||||||
|
template: &mut Option<String>,
|
||||||
|
branch: &mut Option<String>,
|
||||||
|
) {
|
||||||
|
if template.is_none() {
|
||||||
|
use crate::dx_build_info::{PKG_VERSION_MAJOR, PKG_VERSION_MINOR};
|
||||||
|
*template = Some(DEFAULT_TEMPLATE.to_string());
|
||||||
|
*branch = Some(format!("v{PKG_VERSION_MAJOR}.{PKG_VERSION_MINOR}"));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Prevent hidden cursor if Ctrl+C is pressed when interacting
|
/// Prevent hidden cursor if Ctrl+C is pressed when interacting
|
||||||
/// with cargo-generate's prompts.
|
/// with cargo-generate's prompts.
|
||||||
///
|
///
|
||||||
@@ -230,14 +247,7 @@ pub(crate) mod tests {
|
|||||||
|
|
||||||
pub(crate) fn subcommand(name: &str) -> Command {
|
pub(crate) fn subcommand(name: &str) -> Command {
|
||||||
let mut command = BINARY.command();
|
let mut command = BINARY.command();
|
||||||
command
|
command.arg(name).arg("--yes"); // Skip any questions by choosing default answers.
|
||||||
.arg(name)
|
|
||||||
.arg("--yes") // Skip any questions by choosing default answers.
|
|
||||||
.arg("--subtemplate")
|
|
||||||
// Probably should use some template that doesn't require specifying
|
|
||||||
// either `--subtemplate` or `--option`.
|
|
||||||
// Maybe a simple template in tests/ dir?
|
|
||||||
.arg("Fullstack");
|
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::cli::create::DEFAULT_TEMPLATE;
|
|
||||||
use cargo_generate::{GenerateArgs, TemplatePath};
|
use cargo_generate::{GenerateArgs, TemplatePath};
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Parser)]
|
#[derive(Clone, Debug, Default, Deserialize, Parser)]
|
||||||
@@ -14,8 +13,8 @@ pub struct Init {
|
|||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
|
||||||
/// Template path
|
/// Template path
|
||||||
#[clap(default_value = DEFAULT_TEMPLATE, short, long)]
|
#[clap(short, long)]
|
||||||
template: String,
|
template: Option<String>,
|
||||||
|
|
||||||
/// Branch to select when using `template` from a git repository.
|
/// Branch to select when using `template` from a git repository.
|
||||||
/// Mutually exclusive with: `--revision`, `--tag`.
|
/// Mutually exclusive with: `--revision`, `--tag`.
|
||||||
@@ -53,6 +52,9 @@ impl Init {
|
|||||||
self.name = Some(create::name_from_path(&self.path)?);
|
self.name = Some(create::name_from_path(&self.path)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no template is specified, use the default one and set the branch to the latest release.
|
||||||
|
create::resolve_template_and_branch(&mut self.template, &mut self.branch);
|
||||||
|
|
||||||
let args = GenerateArgs {
|
let args = GenerateArgs {
|
||||||
define: self.option,
|
define: self.option,
|
||||||
destination: Some(self.path),
|
destination: Some(self.path),
|
||||||
@@ -60,7 +62,7 @@ impl Init {
|
|||||||
name: self.name,
|
name: self.name,
|
||||||
silent: self.yes,
|
silent: self.yes,
|
||||||
template_path: TemplatePath {
|
template_path: TemplatePath {
|
||||||
auto_path: Some(self.template),
|
auto_path: self.template,
|
||||||
branch: self.branch,
|
branch: self.branch,
|
||||||
revision: self.revision,
|
revision: self.revision,
|
||||||
subfolder: self.subtemplate,
|
subfolder: self.subtemplate,
|
||||||
|
|||||||
Reference in new issue
Block a user