Compare commits
No commits in common. "4a5435f1c835f340541d0c17888fc26456298b3d" and "25a07e8e7a0dee0f865607c6d1ef1f81326fe243" have entirely different histories.
4a5435f1c8
...
25a07e8e7a
3 changed files with 6 additions and 71 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -197,7 +197,7 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curze"
|
name = "curze"
|
||||||
version = "0.4.0"
|
version = "0.3.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"home",
|
"home",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "curze"
|
name = "curze"
|
||||||
version = "0.4.0"
|
version = "0.3.4"
|
||||||
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
|
||||||
|
|
73
src/main.rs
73
src/main.rs
|
@ -16,9 +16,6 @@ struct Cli {
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// Downloads, builds and installs packages.
|
/// Downloads, builds and installs packages.
|
||||||
Install {
|
Install {
|
||||||
/// Force install even if there are updates.
|
|
||||||
#[arg(short, long)]
|
|
||||||
force: bool,
|
|
||||||
/// Packages to install.
|
/// Packages to install.
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
},
|
},
|
||||||
|
@ -32,13 +29,6 @@ enum Commands {
|
||||||
/// Packages to build.
|
/// Packages to build.
|
||||||
name: Vec<String>,
|
name: Vec<String>,
|
||||||
},
|
},
|
||||||
/// Downloads a package and uses git to checkout a specific branch or tag.
|
|
||||||
Checkout {
|
|
||||||
/// Package to checkout.
|
|
||||||
name: String,
|
|
||||||
/// Branch to grab.
|
|
||||||
branch: String,
|
|
||||||
},
|
|
||||||
/// Purges the package cache, freeing space.
|
/// Purges the package cache, freeing space.
|
||||||
Purge {},
|
Purge {},
|
||||||
}
|
}
|
||||||
|
@ -47,12 +37,12 @@ fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Some(Commands::Install { name, force }) => {
|
Some(Commands::Install { name }) => {
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
println!("EROR: No packages named for install.");
|
println!("EROR: No packages named for install.");
|
||||||
} else {
|
} else {
|
||||||
for package in name {
|
for package in name {
|
||||||
install_package(package.to_string(), force.to_owned());
|
install_package(package.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,55 +64,12 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Commands::Checkout { name, branch }) => {
|
|
||||||
if name.is_empty() {
|
|
||||||
println!("EROR: No packages named for checkout.");
|
|
||||||
} else {
|
|
||||||
checkout_package(name.to_string(), branch.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(Commands::Purge {}) => {purge_package_cache()}
|
Some(Commands::Purge {}) => {purge_package_cache()}
|
||||||
None => {println!("NOTE: Run curze help for subcommands and options.")}
|
None => {println!("NOTE: Run curze help for subcommands and options.")}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkout_package(package: String, branch: String) {
|
fn install_package(package: String) {
|
||||||
println!("NOTE: Checking if {} can be checked out.", package);
|
|
||||||
if gitea::is_package_installable(package.clone()) {
|
|
||||||
println!("NOTE: Preparing to checkout {} at {}.", package, branch);
|
|
||||||
let cache_result = handle_package_cache(package.clone());
|
|
||||||
if cache_result {
|
|
||||||
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. Checkout halted.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
println!("NOTE: Performing checkout of {}.", package);
|
|
||||||
let result_of_pull = Command::new("git")
|
|
||||||
.arg("checkout")
|
|
||||||
.arg(format!("{}", branch))
|
|
||||||
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
|
||||||
.output();
|
|
||||||
if result_of_pull.is_ok() {
|
|
||||||
println!("NOTE: Checkout successful.");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
println!("EROR: Checkout failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("EROR: {} is not a valid package! Checkout halted!", package);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn install_package(package: String, force: bool) {
|
|
||||||
println!("NOTE: Checking if {} can be installed.", package);
|
println!("NOTE: Checking if {} can be installed.", package);
|
||||||
if gitea::is_package_installable(package.clone()) {
|
if gitea::is_package_installable(package.clone()) {
|
||||||
println!("NOTE: Preparing to install {}.", package);
|
println!("NOTE: Preparing to install {}.", package);
|
||||||
|
@ -138,7 +85,7 @@ fn install_package(package: String, force: bool) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if Path::new(&format!("{}/.local/share/curze/{}.version", home, realised_name)).exists() && !force {
|
if Path::new(&format!("{}/.local/share/curze/{}.version", home, realised_name)).exists() {
|
||||||
let package_version_a = fs::read_to_string(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name)).unwrap_or("4294967295".to_string()).replace("\n","").replace("\r\n","");
|
let package_version_a = fs::read_to_string(format!("{}/.local/share/curze/cache/{}/.curze/version", home, realised_name)).unwrap_or("4294967295".to_string()).replace("\n","").replace("\r\n","");
|
||||||
let package_version = package_version_a.parse::<u32>().unwrap_or(0);
|
let package_version = package_version_a.parse::<u32>().unwrap_or(0);
|
||||||
let installed_version_a = fs::read_to_string(format!("{}/.local/share/curze/{}.version", home, realised_name)).unwrap_or("4294967295".to_string()).replace("\n","").replace("\r\n","");
|
let installed_version_a = fs::read_to_string(format!("{}/.local/share/curze/{}.version", home, realised_name)).unwrap_or("4294967295".to_string()).replace("\n","").replace("\r\n","");
|
||||||
|
@ -314,18 +261,6 @@ fn handle_package_cache(package: String) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if Path::new(&format!("{}/.local/share/curze/cache/{}/", home, realised_name)).exists() {
|
if Path::new(&format!("{}/.local/share/curze/cache/{}/", home, realised_name)).exists() {
|
||||||
println!("NOTE: Clearing potential unchanged files.");
|
|
||||||
let result_of_pull = Command::new("git")
|
|
||||||
.arg("reset")
|
|
||||||
.arg("--hard")
|
|
||||||
.current_dir(format!("{}/.local/share/curze/cache/{}", home, realised_name))
|
|
||||||
.output();
|
|
||||||
if result_of_pull.is_ok() {
|
|
||||||
println!("NOTE: Clear successful.");
|
|
||||||
} else {
|
|
||||||
println!("WARN: Clear failed. Upstream updates not downloaded. Installation will continue.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
println!("NOTE: Pulling latest changes of {}.", package);
|
println!("NOTE: Pulling latest changes of {}.", package);
|
||||||
let result_of_pull = Command::new("git")
|
let result_of_pull = Command::new("git")
|
||||||
.arg("pull")
|
.arg("pull")
|
||||||
|
|
Reference in a new issue