Treat any bare word in the command line as a report name
This commit is contained in:
@@ -4,7 +4,7 @@ pub(crate) mod add;
|
||||
pub(crate) mod gc;
|
||||
pub(crate) mod help;
|
||||
pub(crate) mod info;
|
||||
pub(crate) mod list;
|
||||
pub(crate) mod modify;
|
||||
pub(crate) mod report;
|
||||
pub(crate) mod sync;
|
||||
pub(crate) mod version;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::argparse::Report;
|
||||
use crate::argparse::Filter;
|
||||
use crate::invocation::display_report;
|
||||
use failure::Fallible;
|
||||
use taskchampion::Replica;
|
||||
@@ -7,35 +7,33 @@ use termcolor::WriteColor;
|
||||
pub(crate) fn execute<W: WriteColor>(
|
||||
w: &mut W,
|
||||
replica: &mut Replica,
|
||||
report: Report,
|
||||
report_name: String,
|
||||
filter: Filter,
|
||||
) -> Fallible<()> {
|
||||
display_report(w, replica, &report)
|
||||
display_report(w, replica, report_name, filter)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::argparse::{Column, Filter, Property};
|
||||
use crate::argparse::Filter;
|
||||
use crate::invocation::test::*;
|
||||
use taskchampion::Status;
|
||||
|
||||
#[test]
|
||||
fn test_list() {
|
||||
fn test_report() {
|
||||
let mut w = test_writer();
|
||||
let mut replica = test_replica();
|
||||
replica.new_task(Status::Pending, s!("my task")).unwrap();
|
||||
|
||||
let report = Report {
|
||||
filter: Filter {
|
||||
..Default::default()
|
||||
},
|
||||
columns: vec![Column {
|
||||
label: "Description".to_owned(),
|
||||
property: Property::Description,
|
||||
}],
|
||||
// The function being tested is only one line long, so this is sort of an integration test
|
||||
// for display_report.
|
||||
|
||||
let report_name = "next".to_owned();
|
||||
let filter = Filter {
|
||||
..Default::default()
|
||||
};
|
||||
execute(&mut w, &mut replica, report).unwrap();
|
||||
execute(&mut w, &mut replica, report_name, filter).unwrap();
|
||||
assert!(w.into_string().contains("my task"));
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,13 @@ pub(crate) fn invoke(command: Command, settings: Config) -> Fallible<()> {
|
||||
} => return cmd::modify::execute(&mut w, &mut replica, filter, modification),
|
||||
|
||||
Command {
|
||||
subcommand: Subcommand::List { report },
|
||||
subcommand:
|
||||
Subcommand::Report {
|
||||
report_name,
|
||||
filter,
|
||||
},
|
||||
..
|
||||
} => return cmd::list::execute(&mut w, &mut replica, report),
|
||||
} => return cmd::report::execute(&mut w, &mut replica, report_name, filter),
|
||||
|
||||
Command {
|
||||
subcommand: Subcommand::Info { filter, debug },
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::argparse::{Column, Property, Report, SortBy};
|
||||
use crate::argparse::Filter;
|
||||
use crate::invocation::filtered_tasks;
|
||||
use crate::report::{Column, Property, Report, Sort, SortBy};
|
||||
use crate::table;
|
||||
use failure::Fallible;
|
||||
use failure::{bail, Fallible};
|
||||
use prettytable::{Row, Table};
|
||||
use std::cmp::Ordering;
|
||||
use taskchampion::{Replica, Task, Uuid};
|
||||
@@ -101,20 +102,64 @@ fn task_column(task: &Task, column: &Column, working_set: &WorkingSet) -> String
|
||||
}
|
||||
}
|
||||
|
||||
fn get_report(report_name: String, filter: Filter) -> Fallible<Report> {
|
||||
let columns = vec![
|
||||
Column {
|
||||
label: "Id".to_owned(),
|
||||
property: Property::Id,
|
||||
},
|
||||
Column {
|
||||
label: "Description".to_owned(),
|
||||
property: Property::Description,
|
||||
},
|
||||
Column {
|
||||
label: "Active".to_owned(),
|
||||
property: Property::Active,
|
||||
},
|
||||
Column {
|
||||
label: "Tags".to_owned(),
|
||||
property: Property::Tags,
|
||||
},
|
||||
];
|
||||
let sort = vec![Sort {
|
||||
ascending: false,
|
||||
sort_by: SortBy::Uuid,
|
||||
}];
|
||||
use crate::argparse::Universe;
|
||||
Ok(match report_name.as_ref() {
|
||||
"list" => Report {
|
||||
columns,
|
||||
sort,
|
||||
filter,
|
||||
},
|
||||
"next" => Report {
|
||||
columns,
|
||||
sort,
|
||||
// TODO: merge invocation filter and report filter
|
||||
filter: Filter {
|
||||
universe: Universe::PendingTasks,
|
||||
..Default::default()
|
||||
},
|
||||
},
|
||||
_ => bail!("Unknown report {:?}", report_name),
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn display_report<W: WriteColor>(
|
||||
w: &mut W,
|
||||
replica: &mut Replica,
|
||||
report: &Report,
|
||||
report_name: String,
|
||||
filter: Filter,
|
||||
) -> Fallible<()> {
|
||||
let mut t = Table::new();
|
||||
|
||||
let report = get_report(report_name, filter)?;
|
||||
let working_set = WorkingSet::new(replica)?;
|
||||
|
||||
// Get the tasks from the filter
|
||||
let mut tasks: Vec<_> = filtered_tasks(replica, &report.filter)?.collect();
|
||||
|
||||
// ..sort them as desired
|
||||
sort_tasks(&mut tasks, report, &working_set);
|
||||
sort_tasks(&mut tasks, &report, &working_set);
|
||||
|
||||
// ..set up the column titles
|
||||
t.set_format(table::format());
|
||||
@@ -138,8 +183,8 @@ pub(super) fn display_report<W: WriteColor>(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::argparse::{Column, Property, Report, Sort, SortBy};
|
||||
use crate::invocation::test::*;
|
||||
use crate::report::Sort;
|
||||
use std::convert::TryInto;
|
||||
use taskchampion::Status;
|
||||
|
||||
@@ -371,4 +416,3 @@ mod test {
|
||||
assert_eq!(task_column(&task, &column, &working_set), s!(""));
|
||||
}
|
||||
}
|
||||
// TODO: test task_column
|
||||
|
||||
Reference in New Issue
Block a user