Browse Source

implementing self update command

tags/v0.3.11-rc1
Shar-jeel-Sajid 10 months ago
parent
commit
2a289a3f31
2 changed files with 52 additions and 0 deletions
  1. +1
    -0
      binaries/cli/Cargo.toml
  2. +51
    -0
      binaries/cli/src/lib.rs

+ 1
- 0
binaries/cli/Cargo.toml View File

@@ -50,6 +50,7 @@ tabwriter = "1.4.0"
log = { version = "0.4.21", features = ["serde"] }
colored = "2.1.0"
env_logger = "0.11.3"
self_update = "0.42.0"
pyo3 = { workspace = true, features = [
"extension-module",
"abi3",


+ 51
- 0
binaries/cli/src/lib.rs View File

@@ -240,6 +240,12 @@ enum Command {
#[clap(long)]
quiet: bool,
},

SelfUpdate {
/// Only check for updates without installing
#[clap(long)]
check_only: bool,
},
}

#[derive(Debug, clap::Args)]
@@ -537,6 +543,51 @@ fn run(args: Args) -> eyre::Result<()> {
.context("failed to run dora-daemon")?
}
Command::Runtime => dora_runtime::main().context("Failed to run dora-runtime")?,
Command::SelfUpdate { check_only } => {
println!("Checking for updates...");

let status = self_update::backends::github::Update::configure()
.repo_owner("dora-rs")
.repo_name("dora")
.bin_name("dora")
.show_download_progress(true)
.current_version(env!("CARGO_PKG_VERSION"))
.build()?;

if check_only {
// Only check if an update is available
match status.get_latest_release() {
Ok(release) => {
let current_version = self_update::cargo_crate_version!();
if current_version != release.version {
println!(
"An update is available: {}. Run 'dora self-update' to update",
release.version
);
} else {
println!(
"Dora CLI is already at the latest version: {}",
current_version
);
}
}
Err(e) => println!("Failed to check for updates: {}", e),
}
} else {
// Perform the actual update
match status.update() {
Ok(update_status) => match update_status {
self_update::Status::UpToDate(version) => {
println!("Dora CLI is already at the latest version: {}", version);
}
self_update::Status::Updated(version) => {
println!("Successfully updated Dora CLI to version: {}", version);
}
},
Err(e) => println!("Failed to update: {}", e),
}
}
}
};

Ok(())


Loading…
Cancel
Save