Allow services with no name

This commit is contained in:
Armaël Guéneau 2024-10-25 22:04:44 +02:00
parent 7e9cfea9e0
commit 9cb4f6c11e
2 changed files with 10 additions and 4 deletions

View file

@ -45,7 +45,7 @@ struct PortRegistration {
job: String,
group: String,
task: String,
service: String,
service: Option<String>,
}
impl Ctx {
@ -139,7 +139,11 @@ fn main() -> Result<ExitCode> {
println!("Conflict in site {}, port {:?}:", &datacenter, port);
for reg in &regs {
println!("- in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"",
reg.file.display(), reg.job, reg.group, reg.task, reg.service)
reg.file.display(), reg.job, reg.group, reg.task,
match &reg.service {
None => "<noname>",
Some(s) => s
})
}
println!()
}

View file

@ -28,7 +28,7 @@ pub struct Task {
#[derive(Deserialize, Debug)]
pub struct Service {
pub name: String,
pub name: Option<String>,
pub tags: Vec<String>,
}
@ -66,7 +66,9 @@ impl Task {
impl Service {
fn from_body(b: &Body) -> Result<Self, String> {
let name = string_from_expr(&attribute_from_body(b, "name")?)?;
let name =
attribute_from_body(b, "name").ok()
.map(|e| string_from_expr(&e)).transpose()?;
let tags = match attribute_from_body(b, "tags") {
Err(_) => Vec::new(),
Ok(tags) => tags_from_expr(&tags)?,