From d44025ed613068fa4c826084d3859f9e176354f1 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 5 Nov 2026 17:50:17 +0800 Subject: [PATCH] refactor: share official runtime install handling --- src/cli/release.rs | 49 +++++++-------------------- src/cli/runtime.rs | 82 ++++++++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 72 deletions(-) diff --git a/src/cli/release.rs b/src/cli/release.rs index ff63b58c..df00b0c6 100644 --- a/src/cli/release.rs +++ b/src/cli/release.rs @@ -1,6 +1,4 @@ -use crate::runtime::{ - InstallRuntimeFromOfficialReleaseOptions, OfficialRuntimePrepareAction, RuntimeService, -}; +use crate::runtime::{InstallRuntimeFromOfficialReleaseOptions, RuntimeService}; use super::{Cli, render}; @@ -112,40 +110,17 @@ impl Cli { "release install uses the canonical runtime name \"{runtime_name}\" for this selector" )); } - if let Some(code) = self.ensure_official_release_host_ready(Some(profile), json_flag)? { - return Ok(code); - } - - let (meta, action) = - self.with_progress(format!("Installing runtime {runtime_name}"), || { - self.runtime_service().prepare_official_openclaw_runtime( - InstallRuntimeFromOfficialReleaseOptions { - name: runtime_name.clone(), - version, - channel, - description, - force, - }, - ) - })?; - - if json_flag { - self.print_json(&meta)?; - return Ok(0); - } - - self.stdout_lines(match action { - OfficialRuntimePrepareAction::Installed => { - render::runtime::runtime_installed(&meta, profile, &self.command_example()) - } - OfficialRuntimePrepareAction::Reused => { - render::runtime::runtime_reused(&meta, profile, &self.command_example()) - } - OfficialRuntimePrepareAction::Updated => { - render::runtime::runtime_updated(&meta, profile, &self.command_example()) - } - }); - Ok(0) + self.install_official_runtime( + InstallRuntimeFromOfficialReleaseOptions { + name: runtime_name, + version, + channel, + description, + force, + }, + json_flag, + profile, + ) } pub(super) fn dispatch_release_command( diff --git a/src/cli/runtime.rs b/src/cli/runtime.rs index 2cd80c28..4065c9a8 100644 --- a/src/cli/runtime.rs +++ b/src/cli/runtime.rs @@ -4,6 +4,7 @@ use crate::runtime::{ OfficialRuntimePrepareAction, RuntimeService, UpdateRuntimeFromReleaseOptions, }; +use super::render::RenderProfile; use super::{Cli, render}; impl Cli { @@ -224,41 +225,17 @@ impl Cli { ); } let name = resolve_official_name()?; - if let Some(code) = - self.ensure_official_release_host_ready(Some(profile), json_flag)? - { - return Ok(code); - } - let (meta, action) = - self.with_progress(format!("Installing runtime {name}"), || { - self.runtime_service().prepare_official_openclaw_runtime( - InstallRuntimeFromOfficialReleaseOptions { - name: name.clone(), - version, - channel, - description, - force, - }, - ) - })?; - - if json_flag { - self.print_json(&meta)?; - return Ok(0); - } - - self.stdout_lines(match action { - OfficialRuntimePrepareAction::Installed => { - render::runtime::runtime_installed(&meta, profile, &self.command_example()) - } - OfficialRuntimePrepareAction::Reused => { - render::runtime::runtime_reused(&meta, profile, &self.command_example()) - } - OfficialRuntimePrepareAction::Updated => { - render::runtime::runtime_updated(&meta, profile, &self.command_example()) - } - }); - return Ok(0); + return self.install_official_runtime( + InstallRuntimeFromOfficialReleaseOptions { + name, + version, + channel, + description, + force, + }, + json_flag, + profile, + ); } (None, None, None) => { return Err( @@ -282,6 +259,41 @@ impl Cli { Ok(0) } + pub(super) fn install_official_runtime( + &self, + options: InstallRuntimeFromOfficialReleaseOptions, + json_flag: bool, + profile: RenderProfile, + ) -> Result { + if let Some(code) = self.ensure_official_release_host_ready(Some(profile), json_flag)? { + return Ok(code); + } + + let (meta, action) = + self.with_progress(format!("Installing runtime {}", options.name), || { + self.runtime_service() + .prepare_official_openclaw_runtime(options) + })?; + + if json_flag { + self.print_json(&meta)?; + return Ok(0); + } + + self.stdout_lines(match action { + OfficialRuntimePrepareAction::Installed => { + render::runtime::runtime_installed(&meta, profile, &self.command_example()) + } + OfficialRuntimePrepareAction::Reused => { + render::runtime::runtime_reused(&meta, profile, &self.command_example()) + } + OfficialRuntimePrepareAction::Updated => { + render::runtime::runtime_updated(&meta, profile, &self.command_example()) + } + }); + Ok(0) + } + pub(super) fn handle_runtime_build_local(&self, args: Vec) -> Result { let (args, json_flag, profile) = self.consume_human_output_flags(args, "runtime build-local")?;