| 90 | impl Init { |
| 91 | #[tracing::instrument(skip(self), target = "cargo_lambda")] |
| 92 | pub async fn run(&mut self) -> Result<()> { |
| 93 | if !self.path.is_dir() { |
| 94 | Err(CreateError::NotADirectoryPath(self.path.to_path_buf()))?; |
| 95 | } |
| 96 | |
| 97 | if self.path.join("Cargo.toml").is_file() { |
| 98 | Err(CreateError::InvalidPackageRoot)?; |
| 99 | } |
| 100 | |
| 101 | let path = dunce::canonicalize(&self.path).map_err(CreateError::InvalidPath)?; |
| 102 | |
| 103 | let name = self |
| 104 | .name |
| 105 | .as_deref() |
| 106 | .or_else(|| path.file_name().and_then(|s| s.to_str())) |
| 107 | .ok_or_else(|| miette::miette!("invalid package name"))?; |
| 108 | |
| 109 | new_project(name, &path, &mut self.config, false).await |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | #[derive(Args, Clone, Debug)] |