File tree Expand file tree Collapse file tree 4 files changed +38
-3
lines changed
Expand file tree Collapse file tree 4 files changed +38
-3
lines changed Original file line number Diff line number Diff 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
307310fn 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
Original file line number Diff line number Diff 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 ( ) ?;
Original file line number Diff line number Diff 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 ( ) ) ,
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments