Skip to main content

vs_core/service/
unuse.rs

1//! Services for removing active version selections from a scope.
2
3use vs_shell::{global_current_dir, project_sdk_dir, remove_existing};
4
5use crate::{App, CoreError, UseScope};
6
7impl App {
8    /// Removes an active tool version from the selected scope.
9    pub fn unuse_tool(&self, plugin_name: &str, scope: UseScope) -> Result<(), CoreError> {
10        match scope {
11            UseScope::Global => {
12                self.write_tool_assignment(
13                    &vs_config::global_tools_file(self.home()),
14                    plugin_name,
15                    None,
16                )?;
17                remove_existing(&global_current_dir(self.runtime_root(), plugin_name))?;
18            }
19            UseScope::Project => {
20                self.write_tool_assignment(&self.preferred_project_file(), plugin_name, None)?;
21                remove_existing(&project_sdk_dir(&self.cwd, plugin_name))?;
22            }
23            UseScope::Session => {
24                let session_file = self.session_file()?;
25                self.write_tool_assignment(&session_file, plugin_name, None)?;
26            }
27        }
28        Ok(())
29    }
30}