summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-03-20 08:46:16 +0200
committerLars Wirzenius <liw@liw.fi>2020-03-20 08:46:16 +0200
commitdcbcbd9457d4bd4d21bcf8dbcc9e416fff463d92 (patch)
treefef50ff7fd2c71e761717c780048bfd29322a87b
parent97654c1795dfb9e84792713911475310e4bc1a86 (diff)
downloadroadmap-dcbcbd9457d4bd4d21bcf8dbcc9e416fff463d92.tar.gz
Change: make error message for wrong number of goals more helpful
-rw-r--r--legend.yaml5
-rw-r--r--src/map.rs17
-rw-r--r--src/step.rs7
3 files changed, 26 insertions, 3 deletions
diff --git a/legend.yaml b/legend.yaml
index fc17ba8..951d369 100644
--- a/legend.yaml
+++ b/legend.yaml
@@ -1,3 +1,8 @@
+goal2: {}
+goal3: {}
+goal4: {}
+goal5: {}
+
goal:
label: |
This is the end goal:
diff --git a/src/map.rs b/src/map.rs
index 77b2feb..c1294bf 100644
--- a/src/map.rs
+++ b/src/map.rs
@@ -27,7 +27,10 @@ impl Roadmap {
// Find steps that nothing depends on.
fn goals(&self) -> Vec<&Step> {
- self.steps.iter().filter(|step| self.is_goal(step)).collect()
+ self.steps
+ .iter()
+ .filter(|step| self.is_goal(step))
+ .collect()
}
/// Count number of steps that nothing depends on.
@@ -125,10 +128,18 @@ impl Roadmap {
// Validate that the parsed, constructed roadmap is valid.
pub fn validate(&self) -> RoadmapResult<()> {
// Is there exactly one goal?
- match self.count_goals() {
+ let goals = self.goals();
+ let n = goals.len();
+ match n {
0 => return Err(format!("the roadmap doesn't have a goal").into()),
1 => (),
- _ => return Err(format!("must have exactly one goal for roadmap").into()),
+ _ => {
+ let mut names: Vec<&str> = goals.iter().map(|s| s.name()).collect();
+ names.sort();
+ let names = names.join(", ");
+ let msg = format!("only one goal allowed, found {}: {}", n, names);
+ return Err(msg.into());
+ }
}
// Does every dependency exist?
diff --git a/src/step.rs b/src/step.rs
index 1ed495b..92b8eec 100644
--- a/src/step.rs
+++ b/src/step.rs
@@ -1,4 +1,5 @@
use super::Status;
+use std::fmt;
/// A roadmap step.
///
@@ -62,6 +63,12 @@ impl Step {
}
}
+impl fmt::Display for Step {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{}", self.name)
+ }
+}
+
#[cfg(test)]
mod tests {
use super::{Status, Step};