Skip to content
Snippets Groups Projects
Commit bef55ad6 authored by Jorge Aparicio's avatar Jorge Aparicio
Browse files

optionally parse tasks.$T.path

parent 7ae2ea2b
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,7 @@ pub struct Init {
pub struct Task {
pub enabled: Option<bool>,
pub path: Option<Path>,
pub priority: Option<u8>,
pub resources: Idents,
}
......@@ -129,16 +130,22 @@ fn tasks(tasks: Option<::Tasks>) -> Result<Tasks> {
tasks
.into_iter()
.map(|(name, task)| {
.map(|(name_, task)| {
let name = name_.clone();
(move || -> Result<_> {
Ok((
name.clone(),
name,
Task {
enabled: task.enabled,
path: task.path,
priority: task.priority,
resources: ::check::idents("resources", task.resources)
.chain_err(|| format!("checking task `{}`", name))?,
resources: ::check::idents(
"resources",
task.resources,
)?,
},
))
})().chain_err(|| format!("checking task `{}`", name_))
})
.collect::<Result<_>>()?
} else {
......
......@@ -50,6 +50,7 @@ pub struct Idle {
#[derive(Debug)]
pub struct Task {
pub enabled: Option<bool>,
pub path: Option<Path>,
pub priority: Option<u8>,
pub resources: Option<Idents>,
}
......
......@@ -319,6 +319,7 @@ fn path(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Path> {
fn task(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Task> {
::parse::delimited(tts, DelimToken::Brace, |tts| {
let mut enabled = None;
let mut path = None;
let mut priority = None;
let mut resources = None;
......@@ -330,6 +331,13 @@ fn task(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Task> {
enabled = Some(::parse::bool(tts.next())
.chain_err(|| "parsing `enabled`")?);
}
"path" => {
ensure!(path.is_none(), "duplicated `path` field");
path = Some(
::parse::path(tts).chain_err(|| "parsing `path`")?,
);
}
"priority" => {
ensure!(priority.is_none(), "duplicated `priority` field");
......@@ -353,6 +361,7 @@ fn task(tts: &mut Peekable<Iter<TokenTree>>) -> Result<Task> {
Ok(Task {
enabled,
path,
priority,
resources,
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment