chore(cli): optimized args handling for init & new (#2418)
This commit is contained in:
1 parent
16313894da
commit
e69c69abd7
2 files changed
+11
-17
No files matched your search
@@ -28,24 +28,20 @@ pub struct Create {
|
||||
|
||||
impl Create {
|
||||
pub fn create(self) -> Result<()> {
|
||||
let mut args = GenerateArgs {
|
||||
let args = GenerateArgs {
|
||||
define: self.option,
|
||||
name: self.name,
|
||||
silent: self.yes,
|
||||
template_path: TemplatePath {
|
||||
auto_path: Some(self.template),
|
||||
subfolder: self.subtemplate,
|
||||
..Default::default()
|
||||
},
|
||||
define: self.option,
|
||||
..Default::default()
|
||||
};
|
||||
if self.yes {
|
||||
if self.name.is_none() {
|
||||
return Err(
|
||||
"You have to provide the project's name when using `--yes` option.".into(),
|
||||
);
|
||||
if self.yes && args.name.is_none() {
|
||||
return Err("You have to provide the project's name when using `--yes` option.".into());
|
||||
}
|
||||
args.silent = true;
|
||||
}
|
||||
args.name = self.name;
|
||||
let path = cargo_generate::generate(args)?;
|
||||
post_create(&path)
|
||||
}
|
||||
|
||||
@@ -29,20 +29,18 @@ impl Init {
|
||||
let name = std::env::current_dir()?
|
||||
.file_name()
|
||||
.map(|f| f.to_str().unwrap().to_string());
|
||||
let mut args = GenerateArgs {
|
||||
let args = GenerateArgs {
|
||||
define: self.option,
|
||||
init: true,
|
||||
name,
|
||||
silent: self.yes,
|
||||
template_path: TemplatePath {
|
||||
auto_path: Some(self.template),
|
||||
subfolder: self.subtemplate,
|
||||
..Default::default()
|
||||
},
|
||||
name,
|
||||
init: true,
|
||||
define: self.option,
|
||||
..Default::default()
|
||||
};
|
||||
if self.yes {
|
||||
args.silent = true;
|
||||
}
|
||||
let path = cargo_generate::generate(args)?;
|
||||
create::post_create(&path)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user