Skip to content

Commit 97ee146

Browse files
committed
make --file command optional
1 parent 3187da0 commit 97ee146

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/base_cli.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub enum Commands {
2020
Test {
2121
/// Sets the YAML test configuration file
2222
#[arg(short, long)]
23-
file: PathBuf,
23+
file: Option<PathBuf>,
2424
},
2525
App {},
2626
}

src/main.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,30 @@ async fn main() {
3838
}
3939
}
4040

41-
async fn cli(file: PathBuf) -> Result<(), anyhow::Error> {
42-
if file.exists() {
43-
let content = fs::read_to_string(file.clone())?;
44-
let ctx = TestContext {
45-
file: file.to_str().unwrap().into(),
46-
file_source: content.clone(),
47-
..Default::default()
48-
};
49-
base_request::run(ctx, content).await
50-
} else {
51-
let files = find_tk_yaml_files(Path::new("."));
52-
for file in files {
41+
async fn cli(file_op: Option<PathBuf>) -> Result<(), anyhow::Error> {
42+
match file_op {
43+
Some(file) => {
5344
let content = fs::read_to_string(file.clone())?;
5445
let ctx = TestContext {
5546
file: file.to_str().unwrap().into(),
5647
file_source: content.clone(),
5748
..Default::default()
5849
};
59-
let _ = base_request::run(ctx, content).await;
50+
base_request::run(ctx, content).await
51+
}
52+
None => {
53+
let files = find_tk_yaml_files(Path::new("."));
54+
for file in files {
55+
let content = fs::read_to_string(file.clone())?;
56+
let ctx = TestContext {
57+
file: file.to_str().unwrap().into(),
58+
file_source: content.clone(),
59+
..Default::default()
60+
};
61+
let _ = base_request::run(ctx, content).await;
62+
}
63+
Ok(())
6064
}
61-
Ok(())
6265
}
6366
}
6467

0 commit comments

Comments
 (0)