From 57b0cda93923d8d7c148ce5256fea8f1a8ab8a68 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Fri, 17 May 2024 16:54:34 +0200 Subject: [PATCH 1/2] fix(cli): Remove owner and spurious informations from templates If a template has an `app.yaml` that contains values for app name, owner, app_id and domain, remove them and substitute usable ones with user-provided values. --- lib/cli/src/commands/app/create.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/cli/src/commands/app/create.rs b/lib/cli/src/commands/app/create.rs index 5a6668a4290..f28096e1d5b 100644 --- a/lib/cli/src/commands/app/create.rs +++ b/lib/cli/src/commands/app/create.rs @@ -454,10 +454,21 @@ impl CmdAppCreate { if app_yaml_path.exists() && app_yaml_path.is_file() { let contents = tokio::fs::read_to_string(&app_yaml_path).await?; - let contents = format!("{contents}\nname: {app_name}"); - let mut app_config = AppConfigV1::parse_yaml(&contents)?; - app_config.owner = Some(owner.to_string()); - let raw_app = serde_yaml::to_string(&app_config)?; + let mut raw_yaml: serde_yaml::Value = serde_yaml::from_str(&contents)?; + match &mut raw_yaml { + serde_yaml::Value::Mapping(m) => { + m.insert("name".into(), app_name.into()); + m.insert("owner".into(), owner.into()); + m.shift_remove("domains"); + m.shift_remove("app_id"); + } + _ => {} + }; + let raw_app = serde_yaml::to_string(&raw_yaml)?; + + // Validate.. + AppConfigV1::parse_yaml(&raw_app)?; + tokio::fs::write(&app_yaml_path, raw_app).await?; } From 52f526db2fa5256fb7e785d462b65b58b7e29388 Mon Sep 17 00:00:00 2001 From: Edoardo Marangoni Date: Fri, 17 May 2024 17:01:21 +0200 Subject: [PATCH 2/2] fix(cli): Make linter happy --- lib/cli/src/commands/app/create.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/cli/src/commands/app/create.rs b/lib/cli/src/commands/app/create.rs index f28096e1d5b..ee945b05678 100644 --- a/lib/cli/src/commands/app/create.rs +++ b/lib/cli/src/commands/app/create.rs @@ -455,15 +455,14 @@ impl CmdAppCreate { if app_yaml_path.exists() && app_yaml_path.is_file() { let contents = tokio::fs::read_to_string(&app_yaml_path).await?; let mut raw_yaml: serde_yaml::Value = serde_yaml::from_str(&contents)?; - match &mut raw_yaml { - serde_yaml::Value::Mapping(m) => { - m.insert("name".into(), app_name.into()); - m.insert("owner".into(), owner.into()); - m.shift_remove("domains"); - m.shift_remove("app_id"); - } - _ => {} + + if let serde_yaml::Value::Mapping(m) = &mut raw_yaml { + m.insert("name".into(), app_name.into()); + m.insert("owner".into(), owner.into()); + m.shift_remove("domains"); + m.shift_remove("app_id"); }; + let raw_app = serde_yaml::to_string(&raw_yaml)?; // Validate..