refactor(command): display command results from special function
This commit is contained in:
parent
4435b375ef
commit
1f90d0acc3
4 changed files with 35 additions and 7 deletions
10
notes.org
10
notes.org
|
|
@ -42,6 +42,16 @@ CLOCK: [2025-05-03 sam. 19:00]--[2025-05-03 sam. 19:05] => 0:05
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:EFFORT: 10min
|
:EFFORT: 10min
|
||||||
:END:
|
:END:
|
||||||
|
:LOGBOOK:
|
||||||
|
CLOCK: [2025-05-03 sam. 19:08]--[2025-05-03 sam. 19:21] => 0:13
|
||||||
|
:END:
|
||||||
|
*** DONE all display of command results must be made via a display method on CommandExecutionResult
|
||||||
|
:PROPERTIES:
|
||||||
|
:EFFORT: 10min
|
||||||
|
:END:
|
||||||
|
:LOGBOOK:
|
||||||
|
CLOCK: [2025-05-03 sam. 21:02]--[2025-05-03 sam. 21:09] => 0:07
|
||||||
|
:END:
|
||||||
** TODO insta test select
|
** TODO insta test select
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:EFFORT: 10min
|
:EFFORT: 10min
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,30 @@ pub enum Command {
|
||||||
|
|
||||||
pub struct CommandExecuteResult {
|
pub struct CommandExecuteResult {
|
||||||
pub should_exit: bool,
|
pub should_exit: bool,
|
||||||
|
msg: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CommandExecuteResult {
|
||||||
|
pub fn display(&self) -> String {
|
||||||
|
self.msg.to_string()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<MetaCommandExecuteResult> for CommandExecuteResult {
|
impl From<MetaCommandExecuteResult> for CommandExecuteResult {
|
||||||
fn from(value: MetaCommandExecuteResult) -> Self {
|
fn from(value: MetaCommandExecuteResult) -> Self {
|
||||||
Self {
|
Self {
|
||||||
should_exit: value.should_exit,
|
should_exit: value.should_exit,
|
||||||
|
msg: String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<StatementExecuteResult> for CommandExecuteResult {
|
impl From<StatementExecuteResult> for CommandExecuteResult {
|
||||||
fn from(_value: StatementExecuteResult) -> Self {
|
fn from(value: StatementExecuteResult) -> Self {
|
||||||
Self { should_exit: false }
|
Self {
|
||||||
|
should_exit: false,
|
||||||
|
msg: value.msg,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ fn main() {
|
||||||
while let Some(input) = read_input() {
|
while let Some(input) = read_input() {
|
||||||
match input.parse::<Command>() {
|
match input.parse::<Command>() {
|
||||||
Ok(cmd) => {
|
Ok(cmd) => {
|
||||||
if cmd.execute().should_exit {
|
let result = cmd.execute();
|
||||||
|
println!("{}", result.display());
|
||||||
|
if result.should_exit {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,19 @@ impl std::str::FromStr for Statement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StatementExecuteResult {}
|
pub struct StatementExecuteResult {
|
||||||
|
pub msg: String,
|
||||||
|
}
|
||||||
|
|
||||||
impl Statement {
|
impl Statement {
|
||||||
pub fn execute(&self) -> StatementExecuteResult {
|
pub fn execute(&self) -> StatementExecuteResult {
|
||||||
match self {
|
match self {
|
||||||
Statement::Insert => println!("insert"),
|
Statement::Insert => StatementExecuteResult {
|
||||||
Statement::Select => println!("select"),
|
msg: String::from("insert"),
|
||||||
}
|
},
|
||||||
StatementExecuteResult {}
|
Statement::Select => StatementExecuteResult {
|
||||||
|
msg: String::from("select"),
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue