forked from code-oss-dev/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.rs
More file actions
48 lines (40 loc) · 1.48 KB
/
update.rs
File metadata and controls
48 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
use indicatif::ProgressBar;
use crate::{
constants::PRODUCT_NAME_LONG,
self_update::SelfUpdate,
update_service::UpdateService,
util::{errors::AnyError, http::ReqwestSimpleHttp, input::ProgressBarReporter},
};
use super::{args::StandaloneUpdateArgs, CommandContext};
pub async fn update(ctx: CommandContext, args: StandaloneUpdateArgs) -> Result<i32, AnyError> {
let update_service = UpdateService::new(
ctx.log.clone(),
ReqwestSimpleHttp::with_client(ctx.http.clone()),
);
let update_service = SelfUpdate::new(&update_service)?;
let current_version = update_service.get_current_release().await?;
if update_service.is_up_to_date_with(¤t_version) {
ctx.log.result(format!(
"{} is already to to date ({})",
PRODUCT_NAME_LONG, current_version.commit
));
return Ok(1);
}
if args.check {
ctx.log
.result(format!("Update to {} is available", current_version));
return Ok(0);
}
let pb = ProgressBar::new(1);
pb.set_message("Downloading...");
update_service
.do_update(¤t_version, ProgressBarReporter::from(pb))
.await?;
ctx.log
.result(format!("Successfully updated to {}", current_version));
Ok(0)
}