MCPcopy Create free account
hub / github.com/Autoparallel/learner / execute_command

Method execute_command

crates/learnerd/src/tui/mod.rs:116–203  ·  view source on GitHub ↗

TODO (autoparallel): This is definitely just replicating what these commands do to an extent. This abstraction isn't good. Executes a given command from the TUI command prompt

(&mut self, command: Commands)

Source from the content-addressed store, hash-verified

114 // This abstraction isn't good.
115 /// Executes a given command from the TUI command prompt
116 pub async fn execute_command(&mut self, command: Commands) -> Result<()> {
117 match command {
118 Commands::Add(args) => {
119 // If PDF flag not specified, show confirmation dialog
120 if !args.pdf && !args.no_pdf {
121 // First add without PDF
122 let paper = add(self, AddArgs { no_pdf: true, ..args }).await?;
123 self.state.dialog = DialogType::PDFConfirm { paper };
124 } else {
125 // Execute with specified flags
126 add(self, args).await?;
127 // Show success dialog
128 self.state.dialog =
129 DialogType::Success { message: "Paper added successfully".to_string() };
130 }
131 self.refresh_papers().await?;
132 },
133 Commands::Remove(args) => {
134 // If not forced, show confirmation first
135 if !args.force {
136 // Find matching papers
137 let mut matching_papers = Vec::new();
138
139 // Get papers matching query
140 let papers = Query::text(&args.query).execute(&mut self.learner.database).await?;
141
142 // Apply filters if any
143 for paper in papers {
144 if let Some(author) = &args.filter.author {
145 if !paper.authors.iter().any(|a| a.name.contains(author)) {
146 continue;
147 }
148 }
149 if let Some(source) = &args.filter.source {
150 if &paper.source.to_string() != source {
151 continue;
152 }
153 }
154 if let Some(before) = &args.filter.before {
155 if !paper.publication_date.to_string().starts_with(before) {
156 continue;
157 }
158 }
159 matching_papers.push(paper);
160 }
161
162 if matching_papers.is_empty() {
163 self.state.set_status_message("No papers found matching criteria".to_string());
164 } else {
165 // Show confirmation dialog
166 self.state.dialog = DialogType::RemoveConfirm { papers: matching_papers, args };
167 }
168 } else {
169 // Execute removal and show success
170 remove(self, args).await?;
171 self.state.dialog =
172 DialogType::Success { message: "Papers removed successfully".to_string() };
173 self.refresh_papers().await?;

Callers 1

runMethod · 0.80

Calls 7

addFunction · 0.85
removeFunction · 0.85
DaemonClass · 0.85
refresh_papersMethod · 0.80
is_emptyMethod · 0.80
set_status_messageMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected