Skip to main content

dev_prune/commands/
daemon.rs

1// Copyright 2026 VKrishna04
2// SPDX-License-Identifier: Apache-2.0
3
4// Handler for the `dev-prune daemon` command.
5//
6// Manages the OS-native background scheduler (install, uninstall, status).
7
8use anyhow::Result;
9
10use crate::daemon;
11use crate::output;
12
13/// Show daemon status.
14pub fn run_status() -> Result<()> {
15    output::print_header("dev-prune daemon status");
16    let status = daemon::daemon_status()?;
17    output::print_info(&format!("Status: {status}"));
18    Ok(())
19}
20
21/// Install the daemon.
22pub fn run_install() -> Result<()> {
23    output::print_header("dev-prune daemon install");
24    let settings = crate::config::Registry::load()
25        .map(|r| r.settings)
26        .unwrap_or_default();
27    daemon::install_daemon(settings.check_interval_days)?;
28    output::print_success("Background daemon installed successfully");
29    output::print_info(&format!(
30        "dev-prune will run automatically every {} day(s), pruning repos idle for {}+ days.",
31        settings.check_interval_days.max(1),
32        settings.idle_days
33    ));
34    output::print_info(
35        "Background runs are non-interactive: they prune every idle repo whose lockfile \
36         verifies, without asking. Change the cadence with `devp config set check_interval_days <n>`, \
37         or remove it with `devp daemon uninstall`.",
38    );
39    Ok(())
40}
41
42/// Uninstall the daemon.
43pub fn run_uninstall() -> Result<()> {
44    output::print_header("dev-prune daemon uninstall");
45    daemon::uninstall_daemon()?;
46    output::print_success("Background daemon removed");
47    Ok(())
48}