From 711d51090ea4b059e82d47eb0ff39104401787db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Fri, 2 May 2025 20:46:08 +0200 Subject: [PATCH] refactor(meta-command): have execute be a member function --- src/main.rs | 7 +++---- src/meta_commands.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 92e577c..46092c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,18 @@ use osdb::branding::startup_msg; use osdb::cli::read_input; use osdb::command::Command; -use osdb::meta_commands::MetaCommand; fn main() { startup_msg(); while let Some(input) = read_input() { match input.parse() { Ok(cmd) => match cmd { - Command::MetaCommand(cmd) => match cmd { - MetaCommand::Exit => { + Command::MetaCommand(cmd) => { + if cmd.execute().should_exit { println!("Good-bye"); break; } - }, + } Command::Statement(stmt) => stmt.execute(), }, Err(err) => eprintln!("{err}"), diff --git a/src/meta_commands.rs b/src/meta_commands.rs index 827707b..8f5368f 100644 --- a/src/meta_commands.rs +++ b/src/meta_commands.rs @@ -2,6 +2,18 @@ pub enum MetaCommand { Exit, } +pub struct MetaCommandExecuteResult { + pub should_exit: bool, +} + +impl MetaCommand { + pub fn execute(&self) -> MetaCommandExecuteResult { + match self { + MetaCommand::Exit => MetaCommandExecuteResult { should_exit: true }, + } + } +} + pub enum MetaCommandParseError { Unrecognized { cmd: String }, }