mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
refactor to a library, add integration tests
This commit is contained in:
parent
9f310c76bd
commit
d0744d5178
8 changed files with 56 additions and 59 deletions
18
src/lib.rs
Normal file
18
src/lib.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
#![recursion_limit = "1024"]
|
||||
|
||||
extern crate chrono;
|
||||
extern crate uuid;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
mod tdb2;
|
||||
mod task;
|
||||
mod errors;
|
||||
|
||||
use std::io::BufRead;
|
||||
pub use task::*;
|
||||
pub use errors::*;
|
||||
|
||||
pub fn parse(filename: &str, reader: impl BufRead) -> Result<Vec<Task>> {
|
||||
Ok(tdb2::parse(filename, reader)?)
|
||||
}
|
47
src/main.rs
47
src/main.rs
|
@ -1,47 +0,0 @@
|
|||
#![recursion_limit = "1024"]
|
||||
|
||||
extern crate chrono;
|
||||
extern crate uuid;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
mod tdb2;
|
||||
mod task;
|
||||
mod errors;
|
||||
|
||||
use tdb2::parse;
|
||||
use std::io::stdin;
|
||||
|
||||
use errors::*;
|
||||
|
||||
fn main() {
|
||||
if let Err(ref e) = run() {
|
||||
use std::io::Write;
|
||||
let stderr = &mut ::std::io::stderr();
|
||||
let errmsg = "Error writing to stderr";
|
||||
|
||||
writeln!(stderr, "error: {}", e).expect(errmsg);
|
||||
|
||||
for e in e.iter().skip(1) {
|
||||
writeln!(stderr, "caused by: {}", e).expect(errmsg);
|
||||
}
|
||||
|
||||
// The backtrace is not always generated. Try to run this example
|
||||
// with `RUST_BACKTRACE=1`.
|
||||
if let Some(backtrace) = e.backtrace() {
|
||||
writeln!(stderr, "backtrace: {:?}", backtrace).expect(errmsg);
|
||||
}
|
||||
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
let input = stdin();
|
||||
parse("<stdin>".to_string(), input.lock())?
|
||||
.iter()
|
||||
.for_each(|t| {
|
||||
println!("{:?}", t);
|
||||
});
|
||||
Ok(())
|
||||
}
|
|
@ -97,6 +97,7 @@ impl TaskBuilder {
|
|||
const ANNOTATION_PREFIX: &str = "annotation_";
|
||||
if name.starts_with(ANNOTATION_PREFIX) {
|
||||
let entry = parse_timestamp(&name[ANNOTATION_PREFIX.len()..]).unwrap();
|
||||
// TODO: sort by entry time
|
||||
self.annotations.push(Annotation {
|
||||
entry,
|
||||
description: value.to_string(),
|
||||
|
|
|
@ -10,11 +10,11 @@ use task::Task;
|
|||
use self::ff4::parse_ff4;
|
||||
use self::errors::*;
|
||||
|
||||
pub(super) fn parse(filename: String, reader: impl BufRead) -> Result<Vec<Task>> {
|
||||
pub(crate) fn parse(filename: &str, reader: impl BufRead) -> Result<Vec<Task>> {
|
||||
let mut tasks = vec![];
|
||||
for (i, line) in reader.lines().enumerate() {
|
||||
tasks.push(parse_ff4(&line?).chain_err(|| {
|
||||
ErrorKind::ParseError(filename.clone(), i as u64 + 1)
|
||||
ErrorKind::ParseError(filename.to_string(), i as u64 + 1)
|
||||
})?);
|
||||
}
|
||||
Ok(tasks)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue