resq_cli/commands/
explore.rs1use anyhow::{Context, Result};
20use clap::Parser;
21use std::process::Command;
22
23#[derive(Parser, Debug)]
25pub struct ExploreArgs {
26 #[arg(default_value = "http://localhost:3000/admin/status")]
28 pub url: String,
29 #[arg(long, default_value_t = 500)]
31 pub refresh_ms: u64,
32}
33
34#[derive(Parser, Debug)]
36pub struct LogsArgs {
37 #[arg(long, default_value = "docker")]
39 pub source: String,
40 #[arg(long)]
42 pub service: Option<String>,
43}
44
45#[derive(Parser, Debug)]
47pub struct HealthArgs {
48 #[arg(short, long, default_value_t = 5)]
50 pub interval: u64,
51}
52
53#[derive(Parser, Debug)]
55pub struct DeployArgs {
56 #[arg(long, default_value = "dev")]
58 pub env: String,
59 #[arg(long)]
61 pub k8s: bool,
62}
63
64#[derive(Parser, Debug)]
66pub struct CleanArgs {
67 #[arg(long, default_value_t = false)]
69 pub dry_run: bool,
70}
71
72#[derive(Parser, Debug)]
74pub struct AsmArgs {
75 #[arg(long, conflicts_with = "dir")]
77 pub file: Option<String>,
78 #[arg(long, conflicts_with = "file")]
80 pub dir: Option<String>,
81 #[arg(long, default_value_t = false)]
83 pub recursive: bool,
84 #[arg(long)]
86 pub ext: Option<String>,
87 #[arg(long)]
89 pub config: Option<String>,
90 #[arg(long, default_value_t = false)]
92 pub no_cache: bool,
93 #[arg(long, default_value_t = false)]
95 pub rebuild_cache: bool,
96 #[arg(long, default_value_t = false)]
98 pub no_disasm: bool,
99 #[arg(long)]
101 pub max_functions: Option<usize>,
102 #[arg(long, default_value_t = false)]
104 pub tui: bool,
105 #[arg(long, default_value_t = false)]
107 pub plain: bool,
108 #[arg(long, default_value_t = false)]
110 pub json: bool,
111}
112
113pub async fn run_explore(args: ExploreArgs) -> Result<()> {
115 run_tool(
116 "resq-perf",
117 &[&args.url, "--refresh-ms", &args.refresh_ms.to_string()],
118 )
119}
120
121pub async fn run_logs(args: LogsArgs) -> Result<()> {
123 let mut cmd_args = vec!["--source", &args.source];
124 if let Some(ref s) = args.service {
125 cmd_args.push("--service");
126 cmd_args.push(s);
127 }
128 run_tool("resq-logs", &cmd_args)
129}
130
131pub async fn run_health(args: HealthArgs) -> Result<()> {
133 run_tool("resq-health", &["--interval", &args.interval.to_string()])
134}
135
136pub async fn run_deploy(args: DeployArgs) -> Result<()> {
138 let mut cmd_args = vec!["--env", &args.env];
139 if args.k8s {
140 cmd_args.push("--k8s");
141 }
142 run_tool("resq-deploy", &cmd_args)
143}
144
145pub async fn run_clean(args: CleanArgs) -> Result<()> {
147 let mut cmd_args = Vec::new();
148 if args.dry_run {
149 cmd_args.push("--dry-run");
150 }
151 run_tool("resq-clean", &cmd_args)
152}
153
154pub async fn run_asm(args: AsmArgs) -> Result<()> {
156 let mut cmd_args = Vec::new();
157 if let Some(ref file) = args.file {
158 cmd_args.push("--file");
159 cmd_args.push(file);
160 }
161 if let Some(ref dir) = args.dir {
162 cmd_args.push("--dir");
163 cmd_args.push(dir);
164 }
165 if args.recursive {
166 cmd_args.push("--recursive");
167 }
168 if let Some(ref ext) = args.ext {
169 cmd_args.push("--ext");
170 cmd_args.push(ext);
171 }
172 if let Some(ref config) = args.config {
173 cmd_args.push("--config");
174 cmd_args.push(config);
175 }
176 if args.no_cache {
177 cmd_args.push("--no-cache");
178 }
179 if args.rebuild_cache {
180 cmd_args.push("--rebuild-cache");
181 }
182 if args.no_disasm {
183 cmd_args.push("--no-disasm");
184 }
185 let max_functions = args.max_functions.map(|v| v.to_string());
186 if let Some(ref max_functions) = max_functions {
187 cmd_args.push("--max-functions");
188 cmd_args.push(max_functions);
189 }
190 if args.tui {
191 cmd_args.push("--tui");
192 }
193 if args.plain {
194 cmd_args.push("--plain");
195 }
196 if args.json {
197 cmd_args.push("--json");
198 }
199 run_tool("resq-bin", &cmd_args)
200}
201
202fn run_tool(name: &str, args: &[&str]) -> Result<()> {
203 let mut child = Command::new("cargo")
208 .arg("run")
209 .arg("-q")
210 .arg("-p")
211 .arg(name)
212 .arg("--")
213 .args(args)
214 .spawn()
215 .with_context(|| format!("Failed to launch tool: {name}"))?;
216
217 let status = child.wait().context("Tool crashed or was interrupted")?;
218 if !status.success() {
219 }
221 Ok(())
222}