feat: config init platform arg

This commit is contained in:
mrxiaozhuox committed 2022-03-10 11:29:27 +08:00
1 parent 1e24b5b416
commit 91a8ce3169
3 files changed
+15 -4

No files matched your search

+11 -2
View File
@@ -13,6 +13,10 @@ pub enum Config {
#[clap(long)]
#[serde(default)]
force: bool,
/// Project default platform
#[clap(long, default_value = "web")]
platform: String,
},
}
@@ -20,7 +24,11 @@ impl Config {
pub fn config(self) -> Result<()> {
let crate_root = crate::cargo::crate_root()?;
match self {
Config::Init { name, force } => {
Config::Init {
name,
force,
platform,
} => {
let conf_path = crate_root.join("Dioxus.toml");
if conf_path.is_file() && !force {
log::warn!(
@@ -30,7 +38,8 @@ impl Config {
}
let mut file = File::create(conf_path)?;
let content = String::from(include_str!("../../assets/dioxus.toml"))
.replace("{{project-name}}", &name);
.replace("{{project-name}}", &name)
.replace("{{default-platform}}", &platform);
file.write_all(content.as_bytes())?;
log::info!("🚩 Init config file completed.");
}