| 166 | |
| 167 | impl Command for Create { |
| 168 | fn run(&self) -> CliResult<()> { |
| 169 | // Get the tag name |
| 170 | let name = self |
| 171 | .name |
| 172 | .as_ref() |
| 173 | .ok_or_else(|| CliError::InvalidArgument { |
| 174 | message: "Tag name is required".to_string(), |
| 175 | })?; |
| 176 | |
| 177 | // Find the repository |
| 178 | let repo_root = find_repository_root()?; |
| 179 | let repo = Repository::open(&repo_root).map_err(|e| match e { |
| 180 | atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound { |
| 181 | searched_path: path.into(), |
| 182 | }, |
| 183 | other => CliError::Repository(other), |
| 184 | })?; |
| 185 | |
| 186 | // Check for existing tag — fail unless --force |
| 187 | if let Ok(Some(_)) = repo.get_tag(name) { |
| 188 | if self.force { |
| 189 | let _ = repo.delete_tag(name); |
| 190 | } else { |
| 191 | return Err(CliError::InvalidArgument { |
| 192 | message: format!("Tag '{}' already exists. Use --force to overwrite.", name), |
| 193 | }); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Create the tag |
| 198 | let tag = repo |
| 199 | .create_tag(name, self.message.as_deref(), TagKind::Release) |
| 200 | .map_err(|e| match e { |
| 201 | atomic_repository::RepositoryError::TagAlreadyExists { name } => { |
| 202 | CliError::InvalidArgument { |
| 203 | message: format!( |
| 204 | "Tag '{}' already exists. Use --force to overwrite.", |
| 205 | name |
| 206 | ), |
| 207 | } |
| 208 | } |
| 209 | atomic_repository::RepositoryError::InvalidTagName { name, reason } => { |
| 210 | CliError::InvalidArgument { |
| 211 | message: format!("Invalid tag name '{}': {}", name, reason), |
| 212 | } |
| 213 | } |
| 214 | atomic_repository::RepositoryError::ViewNotFound { name } => { |
| 215 | CliError::ViewNotFound { name } |
| 216 | } |
| 217 | other => CliError::Repository(other), |
| 218 | })?; |
| 219 | |
| 220 | // Print success message |
| 221 | if tag.is_annotated() { |
| 222 | print_success(&format!("Created annotated tag: {}", emphasis(&tag.name))); |
| 223 | } else { |
| 224 | print_success(&format!("Created tag: {}", emphasis(&tag.name))); |
| 225 | } |