Skip to content

Commit 67fc1fc

Browse files
committed
ptest: Add list command
The `list` command will show what tests are available. Signed-off-by: David Brown <[email protected]>
1 parent c32ad20 commit 67fc1fc

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

ptest/src/main.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ fn main() -> Result<()> {
4040

4141
let args = Cli::parse();
4242

43-
match args.command {
44-
Commands::Run => (),
45-
}
46-
4743
let workflow_text = fs::read_to_string(&args.workflow)?;
4844
let workflow = YamlLoader::load_from_str(&workflow_text)?;
4945

@@ -52,6 +48,14 @@ fn main() -> Result<()> {
5248

5349
let matrix = Matrix::from_yaml(&workflow);
5450

51+
match args.command {
52+
Commands::List => {
53+
matrix.show();
54+
return Ok(());
55+
}
56+
Commands::Run => (),
57+
}
58+
5559
let mut children = vec![];
5660
let state = State::new(matrix.envs.len());
5761
let st2 = state.clone();
@@ -100,6 +104,8 @@ struct Cli {
100104
enum Commands {
101105
/// Runs the tests.
102106
Run,
107+
/// List available tests.
108+
List,
103109
}
104110

105111
/// State, for printing status.
@@ -246,6 +252,13 @@ impl Matrix {
246252
envs,
247253
}
248254
}
255+
256+
/// Print out all of the feature sets.
257+
fn show(&self) {
258+
for (i, feature) in self.envs.iter().enumerate() {
259+
println!("{:3}. {}", i, feature.simple_textual());
260+
}
261+
}
249262
}
250263

251264
impl FeatureSet {
@@ -304,6 +317,18 @@ impl FeatureSet {
304317

305318
buf
306319
}
320+
321+
/// Generate a simpler textual representation, without showing the environment.
322+
fn simple_textual(&self) -> String {
323+
use std::fmt::Write;
324+
325+
let mut buf = String::new();
326+
for v in &self.values {
327+
write!(&mut buf, " {}", v).unwrap();
328+
}
329+
330+
buf
331+
}
307332
}
308333

309334
fn lookup_matrix(y: &Yaml) -> Option<&Vec<Yaml>> {

0 commit comments

Comments
 (0)