Skip to content

Commit 74149a1

Browse files
author
Greyforge Admin
committed
Reject logs paths viewing flags
1 parent 7954d02 commit 74149a1

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

src/cortex-cli/src/logs_cmd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct LogsCli {
3535
pub json: bool,
3636

3737
/// Show log file paths instead of content
38-
#[arg(long)]
38+
#[arg(long, conflicts_with_all = ["follow", "level", "lines"])]
3939
pub paths: bool,
4040

4141
/// Clear old log files
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use std::fs;
2+
use std::process::Command;
3+
4+
use tempfile::tempdir;
5+
6+
fn combined_output(output: &std::process::Output) -> String {
7+
format!(
8+
"{}{}",
9+
String::from_utf8_lossy(&output.stdout),
10+
String::from_utf8_lossy(&output.stderr)
11+
)
12+
}
13+
14+
#[test]
15+
fn logs_paths_accepts_default_lines() {
16+
let home = tempdir().unwrap();
17+
let cache = tempdir().unwrap();
18+
let logs_dir = cache.path().join("cortex").join("logs");
19+
fs::create_dir_all(&logs_dir).unwrap();
20+
fs::write(logs_dir.join("cortex.log"), "log\n").unwrap();
21+
22+
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
23+
.args(["logs", "--paths"])
24+
.env("HOME", home.path())
25+
.env("XDG_CACHE_HOME", cache.path())
26+
.env_remove("CORTEX_HOME")
27+
.output()
28+
.unwrap();
29+
30+
assert!(
31+
output.status.success(),
32+
"logs --paths should accept default --lines:\n{}",
33+
combined_output(&output)
34+
);
35+
}
36+
37+
#[test]
38+
fn logs_paths_rejects_viewing_flags() {
39+
for args in [
40+
["logs", "--paths", "--follow"].as_slice(),
41+
["logs", "--paths", "--level", "error"].as_slice(),
42+
["logs", "--paths", "--lines", "5"].as_slice(),
43+
] {
44+
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
45+
.args(args)
46+
.output()
47+
.unwrap();
48+
49+
assert!(!output.status.success(), "expected {:?} to fail", args);
50+
let output = combined_output(&output);
51+
assert!(
52+
output.contains("cannot be used with") || output.contains("conflict"),
53+
"expected conflict error for {:?}, got:\n{}",
54+
args,
55+
output
56+
);
57+
}
58+
}

0 commit comments

Comments
 (0)