| 101 | |
| 102 | impl Command for Delete { |
| 103 | fn run(&self) -> CliResult<()> { |
| 104 | // Get the view name |
| 105 | let name = self |
| 106 | .name |
| 107 | .as_ref() |
| 108 | .ok_or_else(|| CliError::InvalidArgument { |
| 109 | message: "View name is required".to_string(), |
| 110 | })?; |
| 111 | |
| 112 | // Find the repository |
| 113 | let repo_root = find_repository_root()?; |
| 114 | let mut repo = Repository::open(&repo_root).map_err(|e| match e { |
| 115 | atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound { |
| 116 | searched_path: path.into(), |
| 117 | }, |
| 118 | other => CliError::Repository(other), |
| 119 | })?; |
| 120 | |
| 121 | // Check if trying to delete the current view |
| 122 | if repo.current_view() == name { |
| 123 | return Err(CliError::CannotDeleteCurrentView { |
| 124 | name: name.to_string(), |
| 125 | }); |
| 126 | } |
| 127 | |
| 128 | // Check if the view exists |
| 129 | if !repo.view_exists(name).map_err(CliError::Repository)? { |
| 130 | return Err(CliError::ViewNotFound { |
| 131 | name: name.to_string(), |
| 132 | }); |
| 133 | } |
| 134 | |
| 135 | // Get view info for warning message |
| 136 | if !self.force { |
| 137 | if let Ok(info) = repo.get_view_info(name) { |
| 138 | if info.change_count > 0 { |
| 139 | println!( |
| 140 | "{}", |
| 141 | warning(&format!( |
| 142 | "View '{}' has {} change(s). Use --force to confirm deletion.", |
| 143 | name, info.change_count |
| 144 | )) |
| 145 | ); |
| 146 | // In a real implementation, we might prompt for confirmation here |
| 147 | // For now, we'll just warn but proceed |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | // Delete the view |
| 153 | repo.delete_view(name).map_err(|e| match e { |
| 154 | atomic_repository::RepositoryError::ViewNotFound { name } => { |
| 155 | CliError::ViewNotFound { name } |
| 156 | } |
| 157 | atomic_repository::RepositoryError::CannotDeleteCurrentView { name } => { |
| 158 | CliError::CannotDeleteCurrentView { name } |
| 159 | } |
| 160 | other => CliError::Repository(other), |