mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-02 23:05:15 +01:00
- Start separating a "standalone" CLI. This is a little awkward with clap- derive, but I got it working. Detection of whether the CLI _is_ standalone is still todo. - Remove the old ad-hoc update code for code-server, and use the update service instead. - Fix some of the "permission denied" errors people got while updating before. We need to rename the old running binary, not just overwrite it.
45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
/*---------------------------------------------------------------------------------------------
|
|
* 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::{
|
|
self_update::SelfUpdate,
|
|
update_service::UpdateService,
|
|
util::{errors::AnyError, 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(), 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!(
|
|
"VS Code is already to to date ({})",
|
|
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)
|
|
}
|