cli/sys/
profile_commands.rs1use anyhow::Result;
2
3use crate::{colors, config::Config};
4
5use super::detect::detect_os_id;
6
7pub async fn handle_profile_enable(config: &Config, item_id: &str, dry_run: bool) -> Result<()> {
8 handle_profile_enable_approved(config, item_id, dry_run, true).await
9}
10
11pub async fn handle_profile_disable(config: &Config, item_id: &str, dry_run: bool) -> Result<()> {
12 handle_profile_disable_approved(config, item_id, dry_run, true).await
13}
14
15pub async fn handle_profile_enable_approved(
16 config: &Config,
17 item_id: &str,
18 dry_run: bool,
19 yes: bool,
20) -> Result<()> {
21 handle_profile_state(config, item_id, true, dry_run, yes).await
22}
23
24pub async fn handle_profile_disable_approved(
25 config: &Config,
26 item_id: &str,
27 dry_run: bool,
28 yes: bool,
29) -> Result<()> {
30 handle_profile_state(config, item_id, false, dry_run, yes).await
31}
32
33async fn handle_profile_state(
34 config: &Config,
35 item_id: &str,
36 enabled: bool,
37 dry_run: bool,
38 yes: bool,
39) -> Result<()> {
40 crate::config::print_presets_note(config);
41 let os_id = detect_os_id().await?;
42 let sys_shell: &'static str = config.shell_type.into();
43 let plan_request = shine_core::runtime::SysProfilePlanRequest {
44 os_id: os_id.clone(),
45 item_id: item_id.to_string(),
46 enabled,
47 };
48 let (runtime, reviewed) = if dry_run {
49 (crate::core_runtime::from_config(config).await?, None)
50 } else {
51 let reviewed = crate::lifecycle_plan::review_plans(
52 config,
53 [crate::lifecycle_plan::LifecyclePlanRequest::sys_profile(
54 plan_request.clone(),
55 )],
56 yes,
57 )
58 .await?
59 .into_iter()
60 .next()
61 .expect("one reviewed Sys profile Plan");
62 let runtime = crate::lifecycle_plan::prepare_runtime(config, &reviewed).await?;
63 (runtime, Some(reviewed))
64 };
65 let report = if let Some(reviewed) = reviewed {
66 runtime
67 .set_sys_profile_approved(plan_request, &reviewed.approval)
68 .await?
69 } else {
70 runtime
71 .preview_sys_profile(shine_core::runtime::SysProfileStateRequest {
72 os_id,
73 item_id: item_id.to_string(),
74 enabled,
75 dry_run,
76 })
77 .await?
78 };
79 let action = if enabled { "enable" } else { "disable" };
80 if dry_run {
81 println!(
82 "{} sys/{item_id}: would {action} shell integration for {sys_shell}",
83 colors::dim("[dry-run]")
84 );
85 return Ok(());
86 }
87 let outcome = report
88 .outcome
89 .expect("Core profile mutation returns an outcome");
90 println!(
91 "{} sys/{item_id}: shell integration {} ({})",
92 colors::symbol("✓"),
93 if enabled { "enabled" } else { "disabled" },
94 outcome.detail
95 );
96 Ok(())
97}