update
This commit is contained in:
parent
4c7c5d88fa
commit
870ec706b3
4 changed files with 30 additions and 4 deletions
|
@ -72,6 +72,21 @@ impl VikunjaAPI {
|
|||
found.title
|
||||
}
|
||||
|
||||
pub fn parse_project_id(&self, project: &str) -> Option<isize> {
|
||||
let project = project.trim_start_matches("#");
|
||||
|
||||
if let Ok(num) = project.parse() {
|
||||
Some(num)
|
||||
} else {
|
||||
Some(
|
||||
self.get_all_projects()
|
||||
.into_iter()
|
||||
.find(|x| x.title.contains(project))?
|
||||
.id,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_all_projects(&self) -> Vec<Project> {
|
||||
let resp = self.get_request("/projects");
|
||||
serde_json::from_str(&resp).unwrap()
|
||||
|
|
|
@ -5,6 +5,7 @@ pub fn get_args() -> clap::ArgMatches {
|
|||
.about("CLI Tool for Vikunja")
|
||||
.arg(arg!(-d --done "Show done tasks too").required(false))
|
||||
.arg(arg!(-f --favorite "Show only favorites").required(false))
|
||||
.arg(arg!(--from <project> "Show only tasks from project").required(false))
|
||||
.subcommand(
|
||||
command!()
|
||||
.name("info")
|
||||
|
|
|
@ -27,7 +27,8 @@ fn main() {
|
|||
_ => {
|
||||
let done = arg.get_flag("done");
|
||||
let fav = arg.get_flag("favorite");
|
||||
ui::task::print_current_tasks(&api, done, fav);
|
||||
let project: Option<&String> = arg.get_one("from");
|
||||
ui::task::print_current_tasks(&api, done, fav, project);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,21 +15,30 @@ fn print_task_oneline(task: &Task, api: &VikunjaAPI) {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn print_current_tasks(api: &VikunjaAPI, done: bool, fav: bool) {
|
||||
pub fn print_current_tasks(api: &VikunjaAPI, done: bool, fav: bool, project: Option<&String>) {
|
||||
let current_tasks = api.get_all_tasks();
|
||||
|
||||
let selection: Vec<_> = if done {
|
||||
let mut selection: Vec<_> = if done {
|
||||
current_tasks
|
||||
} else {
|
||||
current_tasks.into_iter().filter(|x| !x.done).collect()
|
||||
};
|
||||
|
||||
let selection = if fav {
|
||||
selection = if fav {
|
||||
selection.into_iter().filter(|x| x.is_favorite).collect()
|
||||
} else {
|
||||
selection
|
||||
};
|
||||
|
||||
if let Some(project) = project {
|
||||
let p_id = api.parse_project_id(project).unwrap();
|
||||
|
||||
selection = selection
|
||||
.into_iter()
|
||||
.filter(|x| x.project_id == p_id)
|
||||
.collect();
|
||||
}
|
||||
|
||||
for task in selection {
|
||||
print_task_oneline(&task, api);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue