-
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(*): Added Cache & Reinstall Arguments (#13)
- Loading branch information
Showing
8 changed files
with
200 additions
and
68 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,13 +1,13 @@ | ||
[package] | ||
name = "sandbox" | ||
version = "0.1.1" | ||
version = "0.2.1" | ||
edition = "2021" | ||
authors = ["WillKirkmanM <[email protected]>"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { version = "4.2.4", features = ["derive"] } | ||
clap = { version = "4.2.7", features = ["derive"] } | ||
colored = "2.0.0" | ||
flate2 = "1.0.26" | ||
indicatif = "0.17.3" | ||
|
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::path::Path; | ||
|
||
use tokio::fs; | ||
use colored::Colorize; | ||
|
||
use crate::{get_path, get_cache_path}; | ||
|
||
pub async fn ensure_installed() { | ||
let cache_path = get_cache_path(); | ||
|
||
fs::create_dir_all(cache_path).await.unwrap(); | ||
} | ||
|
||
pub async fn clear_cache() { | ||
let cache_path = get_cache_path(); | ||
|
||
let cache_folder_is_empty = fs::read_dir(&cache_path).await.unwrap().next_entry().await.unwrap().is_none(); | ||
|
||
if cache_folder_is_empty { | ||
println!("The Install Cache is {}!", "Empty".bright_green()) | ||
} else { | ||
fs::remove_dir_all(&cache_path).await.unwrap(); | ||
fs::create_dir(&cache_path).await.unwrap(); | ||
|
||
println!("{} Cleared The Install Cache!", "Successfully".bright_green()) | ||
} | ||
} | ||
|
||
pub async fn in_cache(id: impl Into<String>) -> bool { | ||
let id = id.into(); | ||
|
||
let cache_path = get_cache_path(); | ||
|
||
let environment_path = get_path(&id).await; | ||
let tar_name = environment_path.split('/').last().unwrap(); | ||
|
||
let formatted_cache_path = format!("{}{}", cache_path, tar_name); | ||
let tar_in_cache = Path::new(&formatted_cache_path).exists(); | ||
|
||
tar_in_cache | ||
} |
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
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,22 @@ | ||
use crate::id_is_valid; | ||
use crate::download::install; | ||
use crate::uninstall::uninstall; | ||
|
||
use colored::Colorize; | ||
|
||
pub async fn reinstall_environment(id: impl Into<String>) { | ||
let id = id.into(); | ||
|
||
if id_is_valid(&id).await { | ||
reinstall(&id).await; | ||
} else { | ||
println!("The environment ({}) does {} exist! You can search for an environment with\nsandbox --search {}", id.bright_green(), "not".red(), id.bright_green()); | ||
} | ||
} | ||
|
||
pub async fn reinstall(id: impl Into<String>) { | ||
let id = id.into(); | ||
|
||
uninstall(&id).await; | ||
install(&id).await.unwrap(); | ||
} |
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