add uninstall support
This commit is contained in:
parent
c68c0529c7
commit
181dc07fc8
3 changed files with 58 additions and 3 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -197,7 +197,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curze"
|
name = "curze"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"home",
|
"home",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "curze"
|
name = "curze"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
57
src/main.rs
57
src/main.rs
|
@ -19,6 +19,11 @@ enum Commands {
|
||||||
/// Packages to install.
|
/// Packages to install.
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
},
|
},
|
||||||
|
/// Uninstalls a list of packages.
|
||||||
|
Uninstall {
|
||||||
|
/// Packages to uninstall.
|
||||||
|
name: Vec<String>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -34,6 +39,15 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(Commands::Uninstall { name }) => {
|
||||||
|
if name.is_empty() {
|
||||||
|
println!("EROR: No packages named for uninstall.");
|
||||||
|
} else {
|
||||||
|
for package in name {
|
||||||
|
uninstall_package(package.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
None => {println!("NOTE: Run curze help for subcommands and options.")}
|
None => {println!("NOTE: Run curze help for subcommands and options.")}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +95,7 @@ fn install_package(package: String) {
|
||||||
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
||||||
.output();
|
.output();
|
||||||
if result_of_install.is_ok() {
|
if result_of_install.is_ok() {
|
||||||
fs::copy(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name), format!("{}/.local/share/curze/{}.version", home, realised_name));
|
let _ = fs::copy(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name), format!("{}/.local/share/curze/{}.version", home, realised_name));
|
||||||
println!("NOTE: {} successfully installed!", package);
|
println!("NOTE: {} successfully installed!", package);
|
||||||
} else {
|
} else {
|
||||||
println!("EROR: Installation failed!");
|
println!("EROR: Installation failed!");
|
||||||
|
@ -94,6 +108,47 @@ fn install_package(package: String) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn uninstall_package(package: String) {
|
||||||
|
println!("NOTE: Preparing to uninstall {}.", package);
|
||||||
|
|
||||||
|
let realised_name = package.clone().replace("/",".");
|
||||||
|
let home_out = fetch_home_dir();
|
||||||
|
let home;
|
||||||
|
if home_out.is_some() {
|
||||||
|
home = home_out.unwrap().clone();
|
||||||
|
} else {
|
||||||
|
println!("EROR: Your home directory could not be found. Installation halted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if Path::new(&format!("{}/.local/share/curze/{}.version", home, realised_name)).exists() {
|
||||||
|
if Path::new(&format!("{}/.local/share/curze/cache/{}/", home, realised_name)).exists() { }
|
||||||
|
else {
|
||||||
|
println!("NOTE: Local copy of package doesn't exist. Pulling now.");
|
||||||
|
let cache_result = handle_package_cache(package.clone());
|
||||||
|
if cache_result {}
|
||||||
|
else {
|
||||||
|
println!("EROR: Local copy of package cannot be obtained. Uninstallation halted.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("NOTE: Uninstalling {}.", package);
|
||||||
|
let result_of_uninstall = Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(".curze/uninstall.sh")
|
||||||
|
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
||||||
|
.output();
|
||||||
|
if result_of_uninstall.is_ok() {
|
||||||
|
let _ = fs::remove_file(format!("{}/.local/share/curze/{}.version", home, realised_name));
|
||||||
|
println!("NOTE: {} successfully uninstalled!", package);
|
||||||
|
} else {
|
||||||
|
println!("EROR: Uninstallation failed!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("EROR: {} is not installed! Uninstallation halted!", package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_package_cache(package: String) -> bool {
|
fn handle_package_cache(package: String) -> bool {
|
||||||
let realised_name = package.clone().replace("/",".");
|
let realised_name = package.clone().replace("/",".");
|
||||||
let home_out = fetch_home_dir();
|
let home_out = fetch_home_dir();
|
||||||
|
|
Reference in a new issue