my_hypervisor update command to fetch the latest version and updated the installed bin on the system #79
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implementation Spec for Issue #79 —
updateCommandObjective
Add a new
updatesubcommand to the CLI that checks the Forgejo releases API for a newer version, downloads the latest binary asset, and replaces the currently installed binary on the system.Requirements
CARGO_PKG_VERSION, currently0.1.4).--forceis passed), download the appropriate binary asset.doas/sudoif in a privileged path.--checkflag (report only, no download) and--forceflag (download even when current).Files to Create
crates/my_hypervisor-cli/src/commands/update.rs— The new command implementationFiles to Modify
Cargo.toml(workspace root) — Addreqwestandsemverto workspace dependenciescrates/my_hypervisor-cli/Cargo.toml— Addreqwestandsemveras dependenciescrates/my_hypervisor-cli/src/cli.rs— AddUpdateArgsstruct andCommands::Updatevariantcrates/my_hypervisor-cli/src/commands/mod.rs— Addpub mod update;crates/my_hypervisor-cli/src/main.rs— Wire upCommands::Updatein the command dispatchImplementation Plan
Step 1: Add dependencies (
reqwest,semver)Cargo.tomland CLI crateCargo.tomlreqwestwithrustls-tls+json+streamfeatures (no OpenSSL, musl-compatible)semver = "1"for robust version comparisonStep 2: Define CLI args and enum variant
UpdateArgswith--checkand--forceflags incli.rsUpdate(UpdateArgs)variant toCommandsenumStep 3: Register module and wire up command
pub mod update;tocommands/mod.rsmain.rs(early-return arm, no VmManager needed)Step 4: Implement the
updatecommand?limit=1)tag_name, compare viasemvermy_hypervisor, notinit)doas/sudocp)Step 5: Add unit tests
Acceptance Criteria
my_hypervisor updatechecks and updates when newer version existsmy_hypervisor update --checkreports availability without downloadingmy_hypervisor update --forcere-downloads even when versions matchdoas/sudofor privileged binary locationscargo clippy --workspace -- -D warningspassescargo fmt --all -- --checkpassescargo test --workspacepassesNotes
rustls-tlsto maintain musl static build compatibilitystd::env::current_exe()resolves symlinks for correct binary replacementtempfile(already a workspace dep) avoids partial-write corruptionmy_hypervisor-initbinaryTest Results
All tests pass, including 9 new unit tests for the update command.
Implementation Summary
Files Created
crates/my_hypervisor-cli/src/commands/update.rs— Newupdatesubcommand implementation with unit testsFiles Modified
Cargo.toml— Addedreqwestandsemverworkspace dependenciescrates/my_hypervisor-cli/Cargo.toml— Addedreqwest,semver,tempfiledependenciescrates/my_hypervisor-cli/src/cli.rs— AddedUpdateArgsstruct andCommands::Updatevariantcrates/my_hypervisor-cli/src/commands/mod.rs— Registeredupdatemodulecrates/my_hypervisor-cli/src/main.rs— Wired upCommands::UpdatedispatchFeatures
my_hypervisor update— Checks Forgejo releases API, downloads and replaces binary if newer version availablemy_hypervisor update --check— Only reports if update is available, no downloadmy_hypervisor update --force— Forces re-download even when versions matchdoas/sudofallback for privileged binary locationsrustls-tlsfor musl static build compatibilitysemverfor robust version comparisontempfileto avoid partial-write corruption during download