mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-01 20:20:23 +02:00
add some cli parsing stuff
This commit is contained in:
parent
61b2de132b
commit
cfdb266800
9 changed files with 3189 additions and 3 deletions
3098
src/cli/lexer.rs
Normal file
3098
src/cli/lexer.rs
Normal file
File diff suppressed because it is too large
Load diff
1
src/cli/mod.rs
Normal file
1
src/cli/mod.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
mod lexer;
|
|
@ -5,6 +5,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
|
|
||||||
|
mod cli;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod operation;
|
mod operation;
|
||||||
mod replica;
|
mod replica;
|
||||||
|
@ -13,6 +14,7 @@ mod task;
|
||||||
mod taskdb;
|
mod taskdb;
|
||||||
pub mod taskstorage;
|
pub mod taskstorage;
|
||||||
mod tdb2;
|
mod tdb2;
|
||||||
|
mod util;
|
||||||
|
|
||||||
pub use operation::Operation;
|
pub use operation::Operation;
|
||||||
pub use replica::Replica;
|
pub use replica::Replica;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use super::pig::Pig;
|
|
||||||
use crate::task::{Task, TaskBuilder};
|
use crate::task::{Task, TaskBuilder};
|
||||||
|
use crate::util::pig::Pig;
|
||||||
use failure::Fallible;
|
use failure::Fallible;
|
||||||
|
|
||||||
/// Rust implementation of part of utf8_codepoint from Taskwarrior's src/utf8.cpp
|
/// Rust implementation of part of utf8_codepoint from Taskwarrior's src/utf8.cpp
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
//! support for the data structure as a compatibility layer.
|
//! support for the data structure as a compatibility layer.
|
||||||
|
|
||||||
mod ff4;
|
mod ff4;
|
||||||
mod pig;
|
|
||||||
|
|
||||||
use self::ff4::parse_ff4;
|
use self::ff4::parse_ff4;
|
||||||
use crate::task::Task;
|
use crate::task::Task;
|
||||||
|
|
39
src/util/datetime.rs
Normal file
39
src/util/datetime.rs
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
//! A re-implementation of the "Datetime" parsing utility from the Taskwarrior
|
||||||
|
//! source.
|
||||||
|
|
||||||
|
// TODO: this module is not yet implemented
|
||||||
|
|
||||||
|
pub(crate) struct DateTime {}
|
||||||
|
|
||||||
|
impl DateTime {
|
||||||
|
/// Parse a datestamp from a prefix of input and return the number of bytes consumed in the
|
||||||
|
/// input
|
||||||
|
pub(crate) fn parse<S: AsRef<str>>(
|
||||||
|
input: S,
|
||||||
|
format: &'static str,
|
||||||
|
) -> Option<(DateTime, usize)> {
|
||||||
|
let input = input.as_ref();
|
||||||
|
let mut len = input.len();
|
||||||
|
|
||||||
|
// try parsing the whole string and repeatedly drop suffixes until a match
|
||||||
|
while len > 0 {
|
||||||
|
if let Some(str) = input.get(..len) {
|
||||||
|
match str {
|
||||||
|
"2015" => return Some((DateTime {}, len)),
|
||||||
|
"2015-" => return Some((DateTime {}, len)),
|
||||||
|
"9th" => return Some((DateTime {}, len)),
|
||||||
|
"10th" => return Some((DateTime {}, len)),
|
||||||
|
"2015-W01" => return Some((DateTime {}, len)),
|
||||||
|
"2015-02-17" => return Some((DateTime {}, len)),
|
||||||
|
"2013-11-29T22:58:00Z" => return Some((DateTime {}, len)),
|
||||||
|
"315532800" => return Some((DateTime {}, len)),
|
||||||
|
"20131129T225800Z" => return Some((DateTime {}, len)),
|
||||||
|
"today" => return Some((DateTime {}, len)),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len -= 1;
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
44
src/util/duration.rs
Normal file
44
src/util/duration.rs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
//! A re-implementation of the "Duration" parsing utility from the Taskwarrior
|
||||||
|
//! source.
|
||||||
|
|
||||||
|
// TODO: this module is not yet implemented
|
||||||
|
|
||||||
|
pub(crate) struct Duration {}
|
||||||
|
|
||||||
|
impl Duration {
|
||||||
|
/// Parse a duration from a prefix of input and return the number of bytes consumed in the
|
||||||
|
/// input
|
||||||
|
pub(crate) fn parse<S: AsRef<str>>(
|
||||||
|
input: S,
|
||||||
|
format: &'static str,
|
||||||
|
) -> Option<(Duration, usize)> {
|
||||||
|
let input = input.as_ref();
|
||||||
|
let mut len = input.len();
|
||||||
|
|
||||||
|
// try parsing the whole string and repeatedly drop suffixes until a match
|
||||||
|
while len > 0 {
|
||||||
|
if let Some(str) = input.get(..len) {
|
||||||
|
match str {
|
||||||
|
"1w" => return Some((Duration {}, len)),
|
||||||
|
"4w" => return Some((Duration {}, len)),
|
||||||
|
"4weeks" => return Some((Duration {}, len)),
|
||||||
|
"5mo" => return Some((Duration {}, len)),
|
||||||
|
"6 years" => return Some((Duration {}, len)),
|
||||||
|
"3 days" => return Some((Duration {}, len)),
|
||||||
|
"1minute" => return Some((Duration {}, len)),
|
||||||
|
"2hour" => return Some((Duration {}, len)),
|
||||||
|
"1s" => return Some((Duration {}, len)),
|
||||||
|
"1second" => return Some((Duration {}, len)),
|
||||||
|
"PT23H" => return Some((Duration {}, len)),
|
||||||
|
"PT1H" => return Some((Duration {}, len)),
|
||||||
|
"P1Y" => return Some((Duration {}, len)),
|
||||||
|
"P1Y1M1DT1H1M1S" => return Some((Duration {}, len)),
|
||||||
|
"year" => return Some((Duration {}, len)),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len -= 1;
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
3
src/util/mod.rs
Normal file
3
src/util/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub(crate) mod datetime;
|
||||||
|
pub(crate) mod duration;
|
||||||
|
pub(crate) mod pig;
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use failure::Fallible;
|
use failure::Fallible;
|
||||||
|
|
||||||
pub struct Pig<'a> {
|
pub(crate) struct Pig<'a> {
|
||||||
input: &'a [u8],
|
input: &'a [u8],
|
||||||
cursor: usize,
|
cursor: usize,
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue