@@ -7,14 +7,19 @@ use crossterm::style::{
77use dialoguer:: FuzzySelect ;
88use eyre:: Result ;
99
10- use crate :: cli:: chat:: tools:: todo:: TodoState ;
10+ use crate :: cli:: chat:: tools:: todo:: {
11+ TodoListState ,
12+ delete_todo,
13+ get_all_todos,
14+ } ;
1115use crate :: cli:: chat:: {
1216 ChatError ,
1317 ChatSession ,
1418 ChatState ,
1519} ;
1620use crate :: os:: Os ;
1721
22+ /// Defines subcommands that allow users to view and manage todo lists
1823#[ derive( Debug , PartialEq , Subcommand ) ]
1924pub enum TodoSubcommand {
2025 /// Delete all completed to-do lists
@@ -62,15 +67,15 @@ impl TodoSubcommand {
6267 pub async fn execute ( self , os : & mut Os , session : & mut ChatSession ) -> Result < ChatState , ChatError > {
6368 match self {
6469 Self :: ClearFinished => {
65- let ( todos, errors) = match TodoState :: get_all_todos ( os) . await {
70+ let ( todos, errors) = match get_all_todos ( os) . await {
6671 Ok ( res) => res,
6772 Err ( e) => return Err ( ChatError :: Custom ( format ! ( "Could not get to-do lists: {e}" ) . into ( ) ) ) ,
6873 } ;
6974 let mut cleared_one = false ;
7075
7176 for todo_status in todos. iter ( ) {
7277 if todo_status. completed . iter ( ) . all ( |b| * b) {
73- match TodoState :: delete_todo ( os, & todo_status. id ) . await {
78+ match delete_todo ( os, & todo_status. id ) . await {
7479 Ok ( _) => cleared_one = true ,
7580 Err ( e) => {
7681 return Err ( ChatError :: Custom ( format ! ( "Could not delete to-do list: {e}" ) . into ( ) ) ) ;
@@ -119,7 +124,7 @@ impl TodoSubcommand {
119124 execute ! ( session. stderr, style:: Print ( "No to-do lists to view!\n " ) ) ?;
120125 } else if let Some ( index) = fuzzy_select_todos ( & entries, "Select a to-do list to view:" ) {
121126 if index < entries. len ( ) {
122- let list = TodoState :: load ( os, & entries[ index] . id ) . await . map_err ( |e| {
127+ let list = TodoListState :: load ( os, & entries[ index] . id ) . await . map_err ( |e| {
123128 ChatError :: Custom ( format ! ( "Could not load current to-do list: {e}" ) . into ( ) )
124129 } ) ?;
125130 execute ! (
@@ -145,14 +150,14 @@ impl TodoSubcommand {
145150 execute ! ( session. stderr, style:: Print ( "No to-do lists to delete!\n " ) ) ?;
146151 } else if all {
147152 for entry in entries {
148- TodoState :: delete_todo ( os, & entry. id )
153+ delete_todo ( os, & entry. id )
149154 . await
150155 . map_err ( |_e| ChatError :: Custom ( "Could not delete all to-do lists" . into ( ) ) ) ?;
151156 }
152157 execute ! ( session. stderr, style:: Print ( "✔ Deleted all to-do lists!\n " . green( ) ) , ) ?;
153158 } else if let Some ( index) = fuzzy_select_todos ( & entries, "Select a to-do list to delete:" ) {
154159 if index < entries. len ( ) {
155- TodoState :: delete_todo ( os, & entries[ index] . id ) . await . map_err ( |e| {
160+ delete_todo ( os, & entries[ index] . id ) . await . map_err ( |e| {
156161 ChatError :: Custom ( format ! ( "Could not delete the selected to-do list: {e}" ) . into ( ) )
157162 } ) ?;
158163 execute ! (
@@ -174,7 +179,7 @@ impl TodoSubcommand {
174179 /// Convert all to-do list state entries to displayable entries
175180 async fn get_descriptions_and_statuses ( os : & Os ) -> Result < Vec < TodoDisplayEntry > > {
176181 let mut out = Vec :: new ( ) ;
177- let ( todos, _) = TodoState :: get_all_todos ( os) . await ?;
182+ let ( todos, _) = get_all_todos ( os) . await ?;
178183 for todo in todos. iter ( ) {
179184 out. push ( TodoDisplayEntry {
180185 num_completed : todo. completed . iter ( ) . filter ( |b| * * b) . count ( ) ,
0 commit comments