Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Allow building without self-update feature #975

Merged
merged 2 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ description = { workspace = true }
members = ["crates/rustic_testing", "xtask"]

[features]
default = []
default = ["self-update"]
mimalloc = ["dep:mimalloc"]
jemallocator = ["dep:jemallocator-global"]
self-update = ["dep:self_update", "dep:semver"]

[[bin]]
name = "rustic"
Expand Down Expand Up @@ -67,8 +68,8 @@ serde_with = { workspace = true }

# other dependencies
chrono = { workspace = true }
self_update = { workspace = true }
semver = { workspace = true }
self_update = { workspace = true, optional = true }
semver = { workspace = true, optional = true }

# commands
clap = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ enum RusticCmd {
ShowConfig(ShowConfigCmd),

/// Update to the latest rustic release
#[cfg_attr(not(feature = "self-update"), clap(hide = true))]
jirutka marked this conversation as resolved.
Show resolved Hide resolved
SelfUpdate(SelfUpdateCmd),

/// Remove unused data or repack repository pack files
Expand Down
13 changes: 9 additions & 4 deletions src/commands/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use crate::{Application, RUSTIC_APP};
use abscissa_core::{status_err, Command, Runnable, Shutdown};

use anyhow::Result;
use self_update::cargo_crate_version;
use semver::Version;

/// `self-update` subcommand
#[derive(clap::Parser, Command, Debug)]
Expand All @@ -26,8 +24,9 @@ impl Runnable for SelfUpdateCmd {
}

impl SelfUpdateCmd {
#[cfg(feature = "self-update")]
fn inner_run(&self) -> Result<()> {
let current_version = Version::parse(cargo_crate_version!())?;
let current_version = semver::Version::parse(self_update::cargo_crate_version!())?;

let release = self_update::backends::github::Update::configure()
.repo_owner("rustic-rs")
Expand All @@ -40,7 +39,7 @@ impl SelfUpdateCmd {

let latest_release = release.get_latest_release()?;

let upstream_version = Version::parse(&latest_release.version)?;
let upstream_version = semver::Version::parse(&latest_release.version)?;

match current_version.cmp(&upstream_version) {
std::cmp::Ordering::Greater => {
Expand All @@ -62,4 +61,10 @@ impl SelfUpdateCmd {

Ok(())
}
#[cfg(not(feature = "self-update"))]
fn inner_run(&self) -> Result<()> {
anyhow::bail!(
"This version of rustic was built without the \"self-update\" feature. Please use your system package manager to update it."
);
}
}