-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathci.rs
More file actions
50 lines (41 loc) · 1.17 KB
/
Copy pathci.rs
File metadata and controls
50 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::{fmt, io::Write};
use anyhow::Result;
use clap::{ValueEnum, builder::PossibleValue};
use crate::{config::Cfg, utils::ExitCode};
pub(crate) fn problem_matcher(flavor: Flavor, cfg: &Cfg<'_>) -> Result<ExitCode> {
print_str(flavor.problem_matcher(), cfg)
}
fn print_str(s: &str, cfg: &Cfg<'_>) -> Result<ExitCode> {
let stdout = cfg.process.stdout();
write!(stdout.lock(), "{s}")?;
Ok(ExitCode::SUCCESS)
}
#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) enum Flavor {
Github,
}
impl Flavor {
fn problem_matcher(&self) -> &'static str {
match self {
Self::Github => include_str!("ci/matcher/github.json"),
}
}
}
impl ValueEnum for Flavor {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Github]
}
fn to_possible_value<'a>(&self) -> Option<PossibleValue> {
Some(match self {
Self::Github => PossibleValue::new("github"),
})
}
}
impl fmt::Display for Flavor {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.to_possible_value() {
Some(v) => write!(f, "{}", v.get_name()),
None => unreachable!(),
}
}
}