Skip to main content

studio_worker/
lib.rs

1//! Library surface for the `studio-worker` binary.
2//!
3//! Exposes the worker's modules so integration tests (and downstream
4//! tooling) can drive the contract without going through the CLI.
5
6pub mod cli;
7pub mod config;
8pub mod engine;
9pub mod http;
10pub mod runtime;
11pub mod service;
12pub mod sys;
13pub mod telemetry;
14#[doc(hidden)]
15pub mod test_support;
16pub mod types;
17#[cfg(feature = "ui")]
18pub mod ui;
19pub mod update;
20
21pub const AGENT_VERSION: &str = env!("CARGO_PKG_VERSION");
22
23/// Sentry release identifier in the `<pkg>@<version>` form expected by
24/// Sentry's organisation-wide *Releases* feature.  Bare version strings
25/// collide across projects in the same org, so we namespace with the
26/// crate name.  Matches what `sentry::release_name!()` would expand to.
27pub const RELEASE_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "@", env!("CARGO_PKG_VERSION"));
28
29/// Dispatch table for the CLI subcommands.  Lives in the library so we
30/// can drive it from tests without invoking the binary.
31pub async fn run_cli(args: cli::Cli) -> anyhow::Result<()> {
32    match args.command {
33        cli::Command::Run => runtime::run(args.config.as_deref()).await,
34        cli::Command::Register {
35            bootstrap_token,
36            api_base_url,
37        } => runtime::register(args.config.as_deref(), bootstrap_token, api_base_url).await,
38        cli::Command::Status => runtime::status(args.config.as_deref()).await,
39        cli::Command::InstallService => service::install(args.config.as_deref()),
40        cli::Command::UninstallService => service::uninstall(),
41        cli::Command::Enable => runtime::set_enabled(args.config.as_deref(), true),
42        cli::Command::Disable => runtime::set_enabled(args.config.as_deref(), false),
43        cli::Command::SetThreshold { gb } => runtime::set_threshold(args.config.as_deref(), gb),
44        cli::Command::Config => runtime::show_config(args.config.as_deref()),
45        cli::Command::CheckUpdate => runtime::check_update(args.config.as_deref()).await,
46        cli::Command::Ui => run_ui(args.config.as_deref()).await,
47    }
48}
49
50#[cfg(feature = "ui")]
51async fn run_ui(config_path: Option<&str>) -> anyhow::Result<()> {
52    ui::run(config_path)
53}
54
55#[cfg(not(feature = "ui"))]
56async fn run_ui(_config_path: Option<&str>) -> anyhow::Result<()> {
57    anyhow::bail!(
58        "this build of studio-worker was compiled without the `ui` cargo feature.\n\
59         Reinstall with `cargo install studio-worker --features ui` (or use the \
60         desktop installer from the releases page) to enable the native UI."
61    )
62}