ct_tracker_lib/projects/stop.rs
1use super::errors;
2use super::persistent;
3use super::ProjectFrame;
4
5/// Stop every project that might be stored in the persistant store, except the one specified
6///
7/// # Returns
8///
9/// Returns `Some(name)` with the name of the stopped project,
10/// if one was stopped, otherwise it returns `None`
11pub fn stored_except(name: &str) -> errors::CtResult<Option<String>> {
12 if let Some(stored) = persistent::has_project()? {
13 if name == stored {
14 // Still return the name, so you can check if your project was already stored
15 Ok(Some(stored))
16 } else {
17 let mut proj = ProjectFrame::load_from_name(stored.as_str())?;
18 proj.stop()?;
19 // The project that has been stopped is returned
20 Ok(Some(stored))
21 }
22 } else {
23 Ok(None)
24 }
25}