Skip to content

Commit

Permalink
Added templ_subdir flag to cargo risczero new (risc0#517)
Browse files Browse the repository at this point in the history
* Adds additional flags to cargo risczero new for sub directory selection
---------

Co-authored-by: Tim Zerrell <[email protected]>
  • Loading branch information
mothran and tzerrell authored Apr 18, 2023
1 parent bdb811a commit 9092149
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions risc0/cargo-risczero/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ pub struct NewCommand {
#[clap(value_parser, long, short, default_value = RISC0_GH_REPO)]
pub template: String,

/// Location of the template
///
/// The subdirectory location of the template used for generating the new
/// project. This path is relative to the base repository specified by
/// --template
#[clap(value_parser, long, default_value = RISC0_TEMPLATE_DIR)]
pub templ_subdir: String,

/// template git tag.
#[clap(value_parser, long, default_value = RISC0_RELEASE_TAG)]
pub tag: String,
Expand Down Expand Up @@ -76,12 +84,6 @@ pub struct NewCommand {
impl NewCommand {
/// Execute this command
pub fn run(&self) {
let subfolder = if self.template == RISC0_GH_REPO {
Some(RISC0_TEMPLATE_DIR.to_string())
} else {
None
};

let dest_dir = if let Some(dest_dir) = self.dest.clone() {
dest_dir
} else {
Expand All @@ -90,7 +92,7 @@ impl NewCommand {

let mut template_path = TemplatePath {
auto_path: Some(self.template.clone()),
subfolder,
subfolder: Some(self.templ_subdir.clone()),
git: None,
branch: None,
path: None,
Expand Down Expand Up @@ -207,6 +209,8 @@ mod tests {
&template_path
.join("templates/rust-starter")
.to_string_lossy(),
"--templ-subdir",
"",
"--dest",
&tmpdir.path().to_string_lossy(),
proj_name,
Expand Down Expand Up @@ -239,6 +243,8 @@ mod tests {
&template_path
.join("templates/rust-starter")
.to_string_lossy(),
"--templ-subdir",
"",
"--dest",
&tmpdir.path().to_string_lossy(),
"--no-git",
Expand Down Expand Up @@ -269,6 +275,8 @@ mod tests {
&template_path
.join("templates/rust-starter")
.to_string_lossy(),
"--templ-subdir",
"",
"--dest",
&tmpdir.path().to_string_lossy(),
"--std",
Expand Down

0 comments on commit 9092149

Please sign in to comment.