| 47 | |
| 48 | #[tokio::main] |
| 49 | async fn main() -> Result<()> { |
| 50 | { |
| 51 | use tracing_subscriber::{fmt, EnvFilter}; |
| 52 | let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); |
| 53 | fmt().with_env_filter(filter).with_ansi(false).init(); |
| 54 | } |
| 55 | |
| 56 | let cli = Cli::parse(); |
| 57 | let client = SupervisorClient::new(&cli.base_url); |
| 58 | |
| 59 | match cli.command { |
| 60 | Commands::Deploy { id, command, args } => { |
| 61 | let config = ProcessConfig { |
| 62 | id, |
| 63 | name: String::new(), |
| 64 | command, |
| 65 | args, |
| 66 | env: Default::default(), |
| 67 | cwd: String::new(), |
| 68 | stdout: String::new(), |
| 69 | stderr: String::new(), |
| 70 | pidfile: String::new(), |
| 71 | cid: None, |
| 72 | note: String::new(), |
| 73 | }; |
| 74 | print_json(&client.deploy(&config).await?); |
| 75 | } |
| 76 | Commands::Start { id } => { |
| 77 | print_json(&client.start(&id).await?); |
| 78 | } |
| 79 | Commands::Stop { id } => { |
| 80 | print_json(&client.stop(&id).await?); |
| 81 | } |
| 82 | Commands::Remove { id } => { |
| 83 | print_json(&client.remove(&id).await?); |
| 84 | } |
| 85 | Commands::List => { |
| 86 | print_json(&client.list().await?); |
| 87 | } |
| 88 | Commands::Info { id } => { |
| 89 | print_json(&client.info(&id).await?); |
| 90 | } |
| 91 | Commands::Ping => { |
| 92 | print_json(&client.ping().await?); |
| 93 | } |
| 94 | Commands::Clear => { |
| 95 | print_json(&client.clear().await?); |
| 96 | } |
| 97 | Commands::Shutdown => { |
| 98 | print_json(&client.shutdown().await?); |
| 99 | } |
| 100 | } |
| 101 | Ok(()) |
| 102 | } |
| 103 | |
| 104 | fn print_json<T: serde::Serialize>(value: &T) { |
| 105 | println!("{}", serde_json::to_string(value).unwrap()); |