forked from DioxusLabs/dioxus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): init cmd can now skip user interaction (DioxusLabs#2412)
Previously only `dx new` had this ability, now `dx init` has it, too.
- Loading branch information
1 parent
010c72c
commit a0962c1
Showing
2 changed files
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,49 @@ | ||
use super::*; | ||
use crate::cli::create::DEFAULT_TEMPLATE; | ||
use cargo_generate::{GenerateArgs, TemplatePath}; | ||
|
||
#[derive(Clone, Debug, Default, Deserialize, Parser)] | ||
#[clap(name = "init")] | ||
pub struct Init { | ||
/// Template path | ||
#[clap(default_value = "gh:dioxuslabs/dioxus-template", long)] | ||
#[clap(default_value = DEFAULT_TEMPLATE, short, long)] | ||
template: String, | ||
/// Pass <option>=<value> for the used template (e.g., `foo=bar`) | ||
#[clap(short, long)] | ||
option: Vec<String>, | ||
/// Specify a sub-template within the template repository to be used as the actual template | ||
#[clap(long)] | ||
subtemplate: Option<String>, | ||
/// Skip user interaction by using the default values for the used template. | ||
/// Default values can be overridden with `--option` | ||
#[clap(short, long)] | ||
yes: bool, | ||
// TODO: turn on/off cargo-generate's output (now is invisible) | ||
// #[clap(default_value = "false", short, long)] | ||
// silent: bool, | ||
} | ||
|
||
impl Init { | ||
pub fn init(self) -> Result<()> { | ||
// get dir name | ||
// Get directory name. | ||
let name = std::env::current_dir()? | ||
.file_name() | ||
.map(|f| f.to_str().unwrap().to_string()); | ||
|
||
let args = GenerateArgs { | ||
let mut args = GenerateArgs { | ||
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) | ||
} | ||
} |