Skip to content

Commit

Permalink
feat: extract into temp directory
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebanBorai committed Oct 1, 2022
1 parent 0b3dc9e commit f8e2e84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
1 change: 1 addition & 0 deletions crates/smdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cargo_metadata = "0.15.0"
cargo-generate = "0.16.0"
convert_case = "0.6.0"
include_dir = "0.7.2"
tempdir = "0.3.7"

fluvio = { path = "../fluvio", default-features = false }
fluvio-protocol = { path = "../fluvio-protocol", features=["record","api"] }
Expand Down
37 changes: 20 additions & 17 deletions crates/smdk/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use anyhow::{Error, Result};
use clap::Parser;
use cargo_generate::{GenerateArgs, TemplatePath, generate};
use include_dir::{Dir, include_dir};
use tempdir::TempDir;

static SMART_MODULE_TEMPLATE: Dir<'_> =
static SMART_MODULE_TEMPLATE: Dir<'static> =
include_dir!("$CARGO_MANIFEST_DIR/../../smartmodule/cargo_template");

/// Generate new SmartModule project
Expand All @@ -22,30 +23,32 @@ impl GenerateOpt {
pub(crate) fn process(self) -> Result<()> {
println!("Generating new SmartModule project: {}", self.name);

let template_path = match self.template {
Some(git) => TemplatePath {
git: Some(git),
let template_path = if self.template.is_some() {
TemplatePath {
git: self.template,
auto_path: None,
subfolder: None,
test: false,
branch: None,
tag: None,
path: None,
favorite: None,
},
None => {
let path = SMART_MODULE_TEMPLATE.path().to_str().unwrap().to_string();
}
} else {
let temp_dir = TempDir::new("smartmodule_template")?;
let path = temp_dir.path().to_str().unwrap().to_string();

SMART_MODULE_TEMPLATE.extract(temp_dir).map_err(Error::from)?;

TemplatePath {
git: None,
auto_path: None,
subfolder: None,
test: false,
branch: None,
tag: None,
path: Some(path),
favorite: None,
}
TemplatePath {
git: None,
auto_path: None,
subfolder: None,
test: false,
branch: None,
tag: None,
path: Some(path),
favorite: None,
}
};

Expand Down

0 comments on commit f8e2e84

Please sign in to comment.