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

Method run

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

Source from the content-addressed store, hash-verified

101
102impl 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),

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