Skip to content

Commit 513e522

Browse files
committed
feat: add --target-tag for version targeting and downgrade
Override the release tag from the embedded update info to install a specific version. Works with all forge-based update info types.
1 parent 52c02f8 commit 513e522

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ struct Cli {
3737
#[arg(short = 'j', long)]
3838
check_for_update: bool,
3939

40+
#[arg(short = 't', long, value_name = "TAG")]
41+
target_tag: Option<String>,
42+
4043
#[arg(
4144
long,
4245
value_name = "URL",
@@ -305,10 +308,16 @@ fn is_appimage(path: &Path) -> bool {
305308
}
306309

307310
fn create_updater(cli: &Cli, path: &Path) -> Result<Updater, Error> {
308-
if let Some(ref info) = cli.update_info {
309-
Updater::with_update_info(path, info)
311+
let updater = if let Some(ref info) = cli.update_info {
312+
Updater::with_update_info(path, info)?
313+
} else {
314+
Updater::new(path)?
315+
};
316+
317+
if let Some(ref tag) = cli.target_tag {
318+
updater.target_tag(tag)
310319
} else {
311-
Updater::new(path)
320+
Ok(updater)
312321
}
313322
}
314323

src/update_info/forge.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ impl ForgeUpdateInfo {
4343
}
4444
}
4545

46+
pub fn set_tag(&mut self, tag: String) {
47+
self.tag = tag;
48+
self.resolved_url = OnceCell::new();
49+
}
50+
4651
pub fn zsync_url(&self) -> Result<&str> {
4752
if self.resolved_url.get().is_none() {
4853
let url = self.resolve_url()?;

src/update_info/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ impl UpdateInfo {
3232
&self.raw
3333
}
3434

35+
pub fn with_target_tag(mut self, tag: &str) -> Self {
36+
if let UpdateInfoInner::Forge(ref mut f) = self.inner {
37+
f.set_tag(tag.to_owned());
38+
}
39+
self
40+
}
41+
42+
pub fn is_forge(&self) -> bool {
43+
matches!(self.inner, UpdateInfoInner::Forge(_))
44+
}
45+
3546
pub fn zsync_url(&self) -> Result<String> {
3647
match &self.inner {
3748
UpdateInfoInner::Generic(g) => Ok(g.zsync_url().to_owned()),

src/updater.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ impl Updater {
9696
self
9797
}
9898

99+
pub fn target_tag(mut self, tag: &str) -> Result<Self> {
100+
if !self.update_info.is_forge() {
101+
return Err(Error::InvalidUpdateInfo(
102+
"--target-tag is only supported for forge-based update info".into(),
103+
));
104+
}
105+
self.update_info = self.update_info.with_target_tag(tag);
106+
Ok(self)
107+
}
108+
99109
pub fn progress_callback<F>(mut self, callback: F) -> Self
100110
where
101111
F: Fn(u64, u64) + Send + Sync + 'static,

0 commit comments

Comments
 (0)