cargo_lambda_system/
lib.rs

1use clap::Args;
2use miette::Result;
3
4use cargo_lambda_build::{Zig, install_options, install_zig, print_install_options};
5use cargo_lambda_interactive::is_stdin_tty;
6use tracing::trace;
7
8#[derive(Args, Clone, Debug)]
9#[command(
10    name = "system",
11    after_help = "Full command documentation: https://www.cargo-lambda.info/commands/system.html"
12)]
13pub struct System {
14    /// Setup and install Zig if it is not already installed.
15    #[arg(long, visible_alias = "install")]
16    setup: bool,
17}
18
19impl System {
20    #[tracing::instrument(skip(self), target = "cargo_lambda")]
21    pub async fn run(&self) -> Result<()> {
22        trace!(options = ?self, "running system command");
23
24        if let Ok((path, _)) = Zig::find_zig() {
25            println!("Zig installation found at:");
26            println!("{}", path.display());
27        } else {
28            let options = install_options();
29            if self.setup && is_stdin_tty() {
30                install_zig(options).await?;
31            } else {
32                print_install_options(&options);
33            }
34        }
35
36        Ok(())
37    }
38}