MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run

Method run

atomic-cli/src/commands/view/delete.rs:106–169  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

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

Callers 5

test_run_without_nameFunction · 0.45
test_delete_current_viewFunction · 0.45

Calls 8

find_repository_rootFunction · 0.85
RepositoryClass · 0.85
print_successFunction · 0.85
as_refMethod · 0.80
current_viewMethod · 0.80
view_existsMethod · 0.80
get_view_infoMethod · 0.80
delete_viewMethod · 0.80

Tested by 5

test_run_without_nameFunction · 0.36
test_delete_current_viewFunction · 0.36