1 (* Implement 'list' subcommand. *)
11 let print_task dbh taskid ?rhbz ?deadline ?estimate description =
20 if Time.equal (Time.midnight ()) (Calendar.to_time deadline) then
21 Printer.Calendar.sprint "%F" deadline
23 Printer.Calendar.to_string deadline in
24 let deadline = " " ^ deadline in
26 cols := !cols + String.length deadline
32 let estimate = " " ^ string_of_estimate period in
34 cols := !cols + String.length estimate
40 printf " https://bugzilla.redhat.com/%ld\n " rhbz;
44 printf " %s" (string_of_task_desc description);
45 cols := !cols + String.length description + 1;
47 let taskid_len = String.length (sprintf "#%ld" taskid) in
48 if !cols + taskid_len >= 78 then (
52 printf " %s" (string_of_taskid taskid);
53 cols := !cols + taskid_len + 1;
55 let rows = PGSQL(dbh) "select tags.name, tags.colour
57 where tags_tasks.taskid = $taskid
58 and tags_tasks.tagid = tags.id
59 order by tags.name" in
62 let len = String.length name + 2 in
63 if !cols + len >= 78 then (
67 printf " %s" (string_of_tag name colour);
68 cols := !cols + len + 1;
72 let cmd_list dbh anon_params list_retired list_all =
73 if anon_params <> [] then
74 error "extra parameters to 'list' subcommand";
76 let show_unretired, show_retired =
77 match list_retired, list_all with
78 | _, true -> true, true
79 | false, false -> true, false
80 | true, false -> false, true in
82 if show_unretired then (
83 let rows = PGSQL(dbh) "select imminent.taskid, tasks.rhbz, tasks.description
85 where imminent.taskid = tasks.id
86 order by tasks.description" in
87 if rows <> [] then heading "Today";
89 fun (id, rhbz, desc) ->
90 print_task dbh id ?rhbz desc
93 let rows = PGSQL(dbh) "select todo.taskid, todo.deadline, todo.estimate,
94 tasks.rhbz, tasks.description
96 where todo.taskid = tasks.id
97 order by todo.deadline, tasks.description" in
98 if rows <> [] then heading "To-do list";
100 fun (id, deadline, estimate, rhbz, desc) ->
101 print_task dbh id ?rhbz ~deadline ?estimate desc
104 let rows = PGSQL(dbh) "
105 select tasks.id, tasks.rhbz, tasks.description
107 where not exists (select 1 from imminent where taskid = tasks.id)
108 and not exists (select 1 from todo where taskid = tasks.id)
109 and not exists (select 1 from ideas where taskid = tasks.id)
110 and not exists (select 1 from retired where taskid = tasks.id)
111 order by tasks.description" in
112 if rows <> [] then heading "Unsorted (use 'todo move' to move these)";
114 fun (id, rhbz, desc) ->
115 print_task dbh id ?rhbz desc
118 let rows = PGSQL(dbh) "select ideas.taskid, tasks.rhbz, tasks.description
120 where ideas.taskid = tasks.id
121 order by tasks.description" in
122 if rows <> [] then heading "Ideas";
124 fun (id, rhbz, desc) ->
125 print_task dbh id ?rhbz desc
129 if show_retired then (
130 let rows = PGSQL(dbh) "select retired.taskid, tasks.rhbz, tasks.description
132 where retired.taskid = tasks.id
133 order by tasks.description" in
134 if rows <> [] then heading "Retired";
136 fun (id, rhbz, desc) ->
137 print_task dbh id ?rhbz desc