1use crate::config::Config;
4use anyhow::Result;
5use shine_core::runtime::{
6 AppArtifactAction, AppArtifactPlanRequest, PlanningInputVersions, RuntimeEvent, RuntimeObserver,
7};
8
9pub async fn handle_build(config: &Config, app_id: &str) -> Result<()> {
10 handle_build_approved(config, app_id, true).await
11}
12
13pub async fn handle_unbuild(config: &Config, app_id: &str) -> Result<()> {
14 handle_unbuild_approved(config, app_id, true).await
15}
16
17pub async fn handle_build_approved(config: &Config, app_id: &str, yes: bool) -> Result<()> {
18 run_explicit(config, app_id, AppArtifactAction::Apply, yes).await
19}
20
21pub async fn handle_unbuild_approved(config: &Config, app_id: &str, yes: bool) -> Result<()> {
22 run_explicit(config, app_id, AppArtifactAction::Remove, yes).await
23}
24
25async fn run_explicit(
26 config: &Config,
27 app_id: &str,
28 action: AppArtifactAction,
29 yes: bool,
30) -> Result<()> {
31 let plan_request = AppArtifactPlanRequest {
32 category: app_id.to_string(),
33 action,
34 input_versions: PlanningInputVersions::default(),
35 };
36 let reviewed = crate::lifecycle_plan::review_plans(
37 config,
38 [crate::lifecycle_plan::LifecyclePlanRequest::app_artifact(
39 plan_request.clone(),
40 config,
41 )],
42 yes,
43 )
44 .await?
45 .into_iter()
46 .next()
47 .expect("one reviewed App artifact Plan");
48 let runtime = crate::lifecycle_plan::prepare_runtime(config, &reviewed).await?;
49 match crate::lifecycle_plan::execute_reviewed(
50 config,
51 runtime,
52 reviewed,
53 shine_core::frontend::ExecutionOptions::default(),
54 &mut ExplicitObserver,
55 &mut crate::presentation::TerminalInteraction,
56 )
57 .await?
58 {
59 shine_core::frontend::OperationDetails::AppArtifact(report) => *report,
60 _ => unreachable!("reviewed operation result type"),
61 };
62 Ok(())
63}
64
65struct ExplicitObserver;
66
67impl RuntimeObserver for ExplicitObserver {
68 fn emit(&mut self, _event: RuntimeEvent) {}
69}