Skip to main content

pitchfork_cli/cli/
mod.rs

1use crate::Result;
2use clap::Parser;
3
4mod activate;
5mod api_schema;
6mod boot;
7mod cd;
8mod clean;
9mod completion;
10mod daemons;
11mod disable;
12mod enable;
13mod list;
14pub mod logs;
15mod mcp;
16mod proxy;
17mod restart;
18mod run;
19mod schema;
20mod settings;
21mod sponsors;
22mod start;
23mod status;
24mod stop;
25mod supervisor;
26mod tui;
27mod usage;
28mod wait;
29
30#[derive(Debug, clap::Parser)]
31#[clap(name = "pitchfork", version = env!("CARGO_PKG_VERSION"), about = env!("CARGO_PKG_DESCRIPTION"))]
32struct Cli {
33    #[clap(subcommand)]
34    command: Commands,
35}
36
37#[derive(Debug, clap::Subcommand)]
38#[allow(clippy::large_enum_variant)]
39enum Commands {
40    Activate(activate::Activate),
41    ApiSchema(api_schema::ApiSchema),
42    Boot(boot::Boot),
43    Cd(cd::Cd),
44    Clean(clean::Clean),
45    Daemons(daemons::Daemons),
46    Completion(completion::Completion),
47    Disable(disable::Disable),
48    Enable(enable::Enable),
49    List(list::List),
50    Logs(logs::Logs),
51    Mcp(mcp::Mcp),
52    Proxy(proxy::Proxy),
53    Restart(restart::Restart),
54    Run(run::Run),
55    Schema(schema::Schema),
56    Settings(settings::Settings),
57    Sponsors(sponsors::Sponsors),
58    Start(start::Start),
59    Status(status::Status),
60    Stop(stop::Stop),
61    Supervisor(supervisor::Supervisor),
62    Tui(tui::Tui),
63    Usage(usage::Usage),
64    Wait(wait::Wait),
65}
66
67pub async fn run() -> Result<()> {
68    let args = Cli::parse();
69    match args.command {
70        Commands::Activate(activate) => activate.run().await,
71        Commands::Boot(boot) => boot.run().await,
72        Commands::Cd(cd) => cd.run().await,
73        Commands::Clean(clean) => clean.run().await,
74        Commands::Daemons(daemons) => daemons.run().await,
75        Commands::Completion(completion) => completion.run().await,
76        Commands::Disable(disable) => disable.run().await,
77        Commands::Enable(enable) => enable.run().await,
78        Commands::List(list) => list.run().await,
79        Commands::Logs(logs) => logs.run().await,
80        Commands::Mcp(mcp) => mcp.run().await,
81        Commands::Proxy(proxy) => proxy.run().await,
82        Commands::Restart(restart) => restart.run().await,
83        Commands::Run(run) => run.run().await,
84        Commands::ApiSchema(api_schema) => api_schema.run().await,
85        Commands::Schema(schema) => schema.run().await,
86        Commands::Settings(settings) => settings.run().await,
87        Commands::Sponsors(_) => sponsors::Sponsors::run().await,
88        Commands::Start(start) => start.run().await,
89        Commands::Status(status) => status.run().await,
90        Commands::Stop(stop) => stop.run().await,
91        Commands::Supervisor(supervisor) => supervisor.run().await,
92        Commands::Tui(tui) => tui.run().await,
93        Commands::Usage(usage) => usage.run().await,
94        Commands::Wait(wait) => wait.run().await,
95    }
96}
97
98/// Drain and display any pending notifications from the supervisor.
99///
100/// Notifications are queued by the supervisor for events that happen
101/// asynchronously (e.g. proxy bind failure) and would otherwise be invisible
102/// to CLI users.  Call this at the end of user-facing commands that connect
103/// to the supervisor via IPC.
104pub(crate) async fn drain_notifications(ipc: &crate::ipc::client::IpcClient) {
105    use log::LevelFilter;
106    if let Ok(notifications) = ipc.get_notifications().await {
107        for (level, msg) in notifications {
108            match level {
109                LevelFilter::Trace => trace!("{msg}"),
110                LevelFilter::Debug => debug!("{msg}"),
111                LevelFilter::Info => info!("{msg}"),
112                LevelFilter::Warn => warn!("{msg}"),
113                LevelFilter::Error => error!("{msg}"),
114                _ => {}
115            }
116        }
117    }
118}