refactor(meta-command): have execute be a member function
This commit is contained in:
parent
ee23572983
commit
711d51090e
2 changed files with 15 additions and 4 deletions
|
|
@ -1,19 +1,18 @@
|
||||||
use osdb::branding::startup_msg;
|
use osdb::branding::startup_msg;
|
||||||
use osdb::cli::read_input;
|
use osdb::cli::read_input;
|
||||||
use osdb::command::Command;
|
use osdb::command::Command;
|
||||||
use osdb::meta_commands::MetaCommand;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
startup_msg();
|
startup_msg();
|
||||||
while let Some(input) = read_input() {
|
while let Some(input) = read_input() {
|
||||||
match input.parse() {
|
match input.parse() {
|
||||||
Ok(cmd) => match cmd {
|
Ok(cmd) => match cmd {
|
||||||
Command::MetaCommand(cmd) => match cmd {
|
Command::MetaCommand(cmd) => {
|
||||||
MetaCommand::Exit => {
|
if cmd.execute().should_exit {
|
||||||
println!("Good-bye");
|
println!("Good-bye");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Command::Statement(stmt) => stmt.execute(),
|
Command::Statement(stmt) => stmt.execute(),
|
||||||
},
|
},
|
||||||
Err(err) => eprintln!("{err}"),
|
Err(err) => eprintln!("{err}"),
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,18 @@ pub enum MetaCommand {
|
||||||
Exit,
|
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 {
|
pub enum MetaCommandParseError {
|
||||||
Unrecognized { cmd: String },
|
Unrecognized { cmd: String },
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue