Support parsing depends:.. in CLI

This commit is contained in:
Dustin J. Mitchell
2022-02-21 22:15:31 +00:00
parent bf73cc4cc7
commit db1e1c9c96
4 changed files with 99 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
use super::{any, timestamp};
use super::{any, id_list, timestamp, TaskId};
use crate::argparse::NOW;
use nom::bytes::complete::tag as nomtag;
use nom::{branch::*, character::complete::*, combinator::*, sequence::*, IResult};
@@ -48,6 +48,17 @@ pub(crate) fn wait_colon(input: &str) -> IResult<&str, Option<DateTime<Utc>>> {
)(input)
}
/// Recognizes `depends:<task>` to `(true, <task>)` and `depends:-<task>` to `(false, <task>)`.
pub(crate) fn depends_colon(input: &str) -> IResult<&str, (bool, Vec<TaskId>)> {
fn to_bool(maybe_minus: Option<char>) -> Result<bool, ()> {
Ok(maybe_minus.is_none()) // None -> true, Some -> false
}
preceded(
nomtag("depends:"),
pair(map_res(opt(char('-')), to_bool), id_list),
)(input)
}
#[cfg(test)]
mod test {
use super::*;

View File

@@ -2,7 +2,7 @@ use nom::{branch::*, character::complete::*, combinator::*, multi::*, sequence::
use taskchampion::Uuid;
/// A task identifier, as given in a filter command-line expression
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub(crate) enum TaskId {
/// A small integer identifying a working-set task
WorkingSetId(usize),

View File

@@ -8,7 +8,7 @@ mod tags;
mod time;
pub(crate) use arg_matching::arg_matching;
pub(crate) use colon::{status_colon, wait_colon};
pub(crate) use colon::{depends_colon, status_colon, wait_colon};
pub(crate) use idlist::{id_list, TaskId};
pub(crate) use misc::{any, literal, report_name};
pub(crate) use tags::{minus_tag, plus_tag};