Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bbd55ecf2 | ||
|
|
104542f784 |
No files matched your search
@@ -183,6 +183,19 @@ fn docker_logs(args: &[String], _verbose: u8) -> Result<()> {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let raw = format!("{}\n{}", stdout, stderr);
|
||||
|
||||
if !output.status.success() {
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track(
|
||||
&format!("docker logs {}", container),
|
||||
"rtk docker logs",
|
||||
&raw,
|
||||
&raw,
|
||||
);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
let analyzed = crate::log_cmd::run_stdin_str(&raw);
|
||||
let rtk = format!("🐳 Logs for {}:\n{}", container, analyzed);
|
||||
println!("{}", rtk);
|
||||
@@ -208,6 +221,15 @@ fn kubectl_pods(args: &[String], _verbose: u8) -> Result<()> {
|
||||
let raw = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
let mut rtk = String::new();
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track("kubectl get pods", "rtk kubectl pods", &raw, &raw);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
let json: serde_json::Value = match serde_json::from_str(&raw) {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
@@ -306,6 +328,15 @@ fn kubectl_services(args: &[String], _verbose: u8) -> Result<()> {
|
||||
let raw = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
let mut rtk = String::new();
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track("kubectl get svc", "rtk kubectl svc", &raw, &raw);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
let json: serde_json::Value = match serde_json::from_str(&raw) {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
@@ -381,6 +412,21 @@ fn kubectl_logs(args: &[String], _verbose: u8) -> Result<()> {
|
||||
|
||||
let output = cmd.output().context("Failed to run kubectl logs")?;
|
||||
let raw = String::from_utf8_lossy(&output.stdout).to_string();
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track(
|
||||
&format!("kubectl logs {}", pod),
|
||||
"rtk kubectl logs",
|
||||
&raw,
|
||||
&raw,
|
||||
);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
let analyzed = crate::log_cmd::run_stdin_str(&raw);
|
||||
let rtk = format!("☸️ Logs for {}:\n{}", pod, analyzed);
|
||||
println!("{}", rtk);
|
||||
|
||||
+17
-12
@@ -77,6 +77,13 @@ pub fn run(
|
||||
let mut by_file: HashMap<String, Vec<(usize, String)>> = HashMap::new();
|
||||
let mut total = 0;
|
||||
|
||||
// Compile context regex once (instead of per-line in clean_line)
|
||||
let context_re = if context_only {
|
||||
Regex::new(&format!("(?i).{{0,20}}{}.*", regex::escape(pattern))).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
for line in stdout.lines() {
|
||||
let parts: Vec<&str> = line.splitn(3, ':').collect();
|
||||
|
||||
@@ -91,7 +98,7 @@ pub fn run(
|
||||
};
|
||||
|
||||
total += 1;
|
||||
let cleaned = clean_line(content, max_line_len, context_only, pattern);
|
||||
let cleaned = clean_line(content, max_line_len, context_re.as_ref(), pattern);
|
||||
by_file.entry(file).or_default().push((line_num, cleaned));
|
||||
}
|
||||
|
||||
@@ -143,16 +150,14 @@ pub fn run(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clean_line(line: &str, max_len: usize, context_only: bool, pattern: &str) -> String {
|
||||
fn clean_line(line: &str, max_len: usize, context_re: Option<&Regex>, pattern: &str) -> String {
|
||||
let trimmed = line.trim();
|
||||
|
||||
if context_only {
|
||||
if let Ok(re) = Regex::new(&format!("(?i).{{0,20}}{}.*", regex::escape(pattern))) {
|
||||
if let Some(m) = re.find(trimmed) {
|
||||
let matched = m.as_str();
|
||||
if matched.len() <= max_len {
|
||||
return matched.to_string();
|
||||
}
|
||||
if let Some(re) = context_re {
|
||||
if let Some(m) = re.find(trimmed) {
|
||||
let matched = m.as_str();
|
||||
if matched.len() <= max_len {
|
||||
return matched.to_string();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,7 +221,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_clean_line() {
|
||||
let line = " const result = someFunction();";
|
||||
let cleaned = clean_line(line, 50, false, "result");
|
||||
let cleaned = clean_line(line, 50, None, "result");
|
||||
assert!(!cleaned.starts_with(' '));
|
||||
assert!(cleaned.len() <= 50);
|
||||
}
|
||||
@@ -240,7 +245,7 @@ mod tests {
|
||||
fn test_clean_line_multibyte() {
|
||||
// Thai text that exceeds max_len in bytes
|
||||
let line = " สวัสดีครับ นี่คือข้อความที่ยาวมากสำหรับทดสอบ ";
|
||||
let cleaned = clean_line(line, 20, false, "ครับ");
|
||||
let cleaned = clean_line(line, 20, None, "ครับ");
|
||||
// Should not panic
|
||||
assert!(!cleaned.is_empty());
|
||||
}
|
||||
@@ -248,7 +253,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_clean_line_emoji() {
|
||||
let line = "🎉🎊🎈🎁🎂🎄 some text 🎃🎆🎇✨";
|
||||
let cleaned = clean_line(line, 15, false, "text");
|
||||
let cleaned = clean_line(line, 15, None, "text");
|
||||
assert!(!cleaned.is_empty());
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -307,7 +307,8 @@ fn run_list(depth: usize, args: &[String], verbose: u8) -> Result<()> {
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
anyhow::bail!("pnpm list failed: {}", stderr);
|
||||
eprint!("{}", stderr);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
@@ -431,7 +432,8 @@ fn run_install(packages: &[String], args: &[String], verbose: u8) -> Result<()>
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
if !output.status.success() {
|
||||
anyhow::bail!("pnpm install failed: {}", stderr);
|
||||
eprint!("{}", stderr);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
let combined = format!("{}{}", stdout, stderr);
|
||||
|
||||
@@ -251,6 +251,12 @@ impl Tracker {
|
||||
}
|
||||
|
||||
let conn = Connection::open(&db_path)?;
|
||||
// WAL mode + busy_timeout for concurrent access (multiple Claude Code instances).
|
||||
// Non-fatal: NFS/read-only filesystems may not support WAL.
|
||||
let _ = conn.execute_batch(
|
||||
"PRAGMA journal_mode=WAL;
|
||||
PRAGMA busy_timeout=5000;",
|
||||
);
|
||||
conn.execute(
|
||||
"CREATE TABLE IF NOT EXISTS commands (
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
||||
+20
-8
@@ -41,10 +41,16 @@ pub fn run(url: &str, args: &[String], verbose: u8) -> Result<()> {
|
||||
println!("{}", msg);
|
||||
timer.track(&format!("wget {}", url), "rtk wget", &raw_output, &msg);
|
||||
} else {
|
||||
let error = parse_error(&stderr, &stdout);
|
||||
let msg = format!("⬇️ {} FAILED: {}", compact_url(url), error);
|
||||
println!("{}", msg);
|
||||
timer.track(&format!("wget {}", url), "rtk wget", &raw_output, &msg);
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track(
|
||||
&format!("wget {}", url),
|
||||
"rtk wget",
|
||||
&raw_output,
|
||||
&raw_output,
|
||||
);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -103,10 +109,16 @@ pub fn run_stdout(url: &str, args: &[String], verbose: u8) -> Result<()> {
|
||||
);
|
||||
} else {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let error = parse_error(&stderr, "");
|
||||
let msg = format!("⬇️ {} FAILED: {}", compact_url(url), error);
|
||||
println!("{}", msg);
|
||||
timer.track(&format!("wget -O - {}", url), "rtk wget -o", &stderr, &msg);
|
||||
if !stderr.trim().is_empty() {
|
||||
eprint!("{}", stderr);
|
||||
}
|
||||
timer.track(
|
||||
&format!("wget -O - {}", url),
|
||||
"rtk wget -o",
|
||||
&stderr,
|
||||
&stderr,
|
||||
);
|
||||
std::process::exit(output.status.code().unwrap_or(1));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in new issue
Block a user