-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(uninstall.rs): Uninstall Command (#10)
- Loading branch information
Showing
8 changed files
with
135 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sandbox" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
edition = "2021" | ||
authors = ["WillKirkmanM <[email protected]>"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,18 @@ | ||
use std::path::Path; | ||
|
||
use colored::Colorize; | ||
|
||
use crate::{get_path, id_is_valid, download::download_environment}; | ||
use crate::id_is_valid; | ||
use crate::download::install; | ||
use crate::in_system; | ||
|
||
pub async fn install_environment(id: String) { | ||
if id_is_valid(id.clone()).await { | ||
if in_system(id.clone()).await { | ||
println!("You already have {} installed on your system!", id.bright_green()); | ||
} else { | ||
download_environment(id.clone()).await.unwrap(); | ||
install(id.clone()).await.unwrap(); | ||
} | ||
} else { | ||
println!("The environment ({}) does {} exist!", id.bright_green(), "not".red()) | ||
} | ||
} | ||
|
||
pub async fn in_system(id: String) -> bool { | ||
let path = get_path(id.clone()).await; | ||
let environment_path = path.split("/").collect::<Vec<&str>>()[0].to_owned() + "/" + &id; | ||
let formatted_path = format!("/usr/share/sandbox/beaches/{}", environment_path); | ||
|
||
let path = Path::new(&formatted_path); | ||
|
||
if path.exists() && path.is_dir() { | ||
true | ||
} else { | ||
false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use crate::install::in_system; | ||
use crate::in_system; | ||
use crate::get_templates_mapping; | ||
|
||
use colored::Colorize; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::env; | ||
use std::io::{stdin, stdout, Write}; | ||
|
||
use crate::{get_path, id_is_valid, in_system}; | ||
|
||
use colored::Colorize; | ||
use tokio::fs; | ||
|
||
pub async fn uninstall_environment(environment: impl Into<String>) { | ||
let environment = environment.into(); | ||
|
||
if id_is_valid(&environment).await { | ||
if in_system(&environment).await { | ||
uninstall(environment).await | ||
} else { | ||
println!( | ||
"You do {} have {} installed! Install it with:\nsandbox --install {}", | ||
"not".red(), | ||
environment.bright_green(), | ||
environment.bright_green() | ||
) | ||
} | ||
} else { | ||
println!("The environment ({}) does {} exist! You can search for an environment with\nsandbox --search {}", environment.bright_green(), "not".red(), environment.bright_green()); | ||
} | ||
} | ||
|
||
pub async fn uninstall(environment: impl Into<String>) { | ||
let environment = environment.into(); | ||
|
||
let base_path = match env::consts::OS { | ||
"windows" => { | ||
let appdata = std::env::var("appdata").unwrap(); | ||
let beaches_path = format!("{}/sandbox/beaches/", appdata); | ||
beaches_path | ||
} | ||
_ => "/usr/share/sandbox/beaches/".to_string(), | ||
}; | ||
|
||
let path = get_path(environment.clone()).await; | ||
let environment_path = path.split("/").collect::<Vec<&str>>()[0].to_owned() + "/" + &environment; | ||
|
||
let formatted_path = format!("{}{}", base_path, environment_path); | ||
|
||
let mut answer = String::new(); | ||
|
||
print!( | ||
"Are you sure you want to delete {}? [{}/{}] ", | ||
&environment.blue(), | ||
"Y".bright_green(), | ||
"n".red() | ||
); | ||
|
||
stdout().lock().flush().unwrap(); | ||
|
||
stdin().read_line(&mut answer).unwrap(); | ||
|
||
answer = answer.trim().into(); | ||
|
||
if answer == "Y" { | ||
match fs::remove_dir_all(formatted_path).await { | ||
Ok(_) => { | ||
println!("Successfully Deleted {} from System!", environment.bright_green()) | ||
}, | ||
Err(err) => { | ||
println!("There was an {} Deleting {}!\n{}", "Erorr".red(), environment.blue(), err) | ||
} | ||
} | ||
} | ||
} |