basic_usage/
basic_usage.rs

1use owo_colors::AnsiColors;
2use prox::{Config, Proc, Prox};
3use std::time::Duration;
4use std::{collections::HashMap, path::PathBuf};
5
6fn main() -> anyhow::Result<()> {
7    // Example: Simple process manager with multiple services
8    let mut manager = Prox::builder()
9        .config(
10            Config::builder()
11                .readiness_fallback_timeout(Duration::from_secs(15))
12                .build(),
13        )
14        .procs(
15            [
16                Proc::builder()
17                    .name("api".into())
18                    .command("cargo".into())
19                    .args(vec!["run".into(), "--bin".into(), "api".into()])
20                    .working_dir(PathBuf::from("./api"))
21                    .readiness_pattern("Server listening".into())
22                    .watch(vec![
23                        PathBuf::from("./api/src"),
24                        PathBuf::from("./shared/src"),
25                    ])
26                    .env(HashMap::from_iter([("LOG_LEVEL".into(), "debug".into())]))
27                    .color(AnsiColors::BrightGreen)
28                    .build(),
29                Proc::builder()
30                    .name("database".into())
31                    .command("docker".into())
32                    .args(["run".into()].into())
33                    .env(
34                        [
35                            ("POSTGRES_DB".into(), "myapp".into()),
36                            ("POSTGRES_PASSWORD".into(), "password".into()),
37                        ]
38                        .into(),
39                    )
40                    .readiness_pattern("database system is ready to accept connections".into())
41                    .build(),
42                Proc::builder()
43                    .name("frontend".into())
44                    .command("npm".into())
45                    .args(vec!["run".into(), "dev".into()])
46                    .working_dir(PathBuf::from("./frontend"))
47                    .readiness_pattern("Local:".into())
48                    .watch(vec![PathBuf::from("./frontend/src")])
49                    .color(AnsiColors::BrightYellow)
50                    .build(),
51            ]
52            .into(),
53        )
54        .build();
55
56    println!("Starting development environment...");
57
58    // Start all processes - this will block until Ctrl+C or a process exits
59    manager.start()?;
60
61    Ok(())
62}