diff --git a/grammar.ebnf b/grammar.ebnf index e979f99..4fefa7b 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -10,6 +10,7 @@ select ::= "select" meta-command ::= "." "exit" | "about" + | "version" int ::= sign? digit+ sign ::= "+" diff --git a/notes.org b/notes.org index 76423a1..c03ef68 100644 --- a/notes.org +++ b/notes.org @@ -226,8 +226,8 @@ i will use rustyline, since it seems like the most feature-complete * DONE write a proper grammar -* TODO .about meta-command -* TODO .version meta-command +* DONE .about meta-command +* DONE .version meta-command * TODO .license meta-command * TODO .help meta-command diff --git a/src/branding.rs b/src/branding.rs index b4418d7..84e1e54 100644 --- a/src/branding.rs +++ b/src/branding.rs @@ -13,12 +13,18 @@ pub fn startup_msg() -> String { ) } -pub fn about_msg() -> String { +pub fn version_msg() -> String { let name = env!("CARGO_PKG_NAME"); let version = env!("CARGO_PKG_VERSION"); + format!("{name} v{version}") +} + +pub fn about_msg() -> String { + let version = version_msg(); + format!( - "{name} v{version} -- A database engine\n\ + "{version} -- A database engine\n\ Note: This is experimental software. No maintenance is intendend." ) } diff --git a/src/meta_commands.rs b/src/meta_commands.rs index d93a079..1bcc2b9 100644 --- a/src/meta_commands.rs +++ b/src/meta_commands.rs @@ -4,6 +4,7 @@ use crate::branding; pub enum MetaCommand { Exit, About, + Version, } impl std::fmt::Display for MetaCommand { @@ -11,6 +12,7 @@ impl std::fmt::Display for MetaCommand { match self { MetaCommand::Exit => write!(f, "exit"), MetaCommand::About => write!(f, "about"), + MetaCommand::Version => write!(f, "version"), } } } @@ -24,9 +26,13 @@ impl MetaCommand { match self { MetaCommand::Exit => MetaCommandExecuteResult { should_exit: true }, MetaCommand::About => { - print!("{}", branding::about_msg()); - MetaCommandExecuteResult { should_exit: false } - } + print!("{}", branding::about_msg()); + MetaCommandExecuteResult { should_exit: false } + } + MetaCommand::Version => { + print!("{}", branding::version_msg()); + MetaCommandExecuteResult { should_exit: false } + }, } } } diff --git a/src/tokens.rs b/src/tokens.rs index 2c3464b..a1a850b 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -161,6 +161,7 @@ impl Tokenizer { match word.to_lowercase().as_str() { ".exit" => Some(TokenData::MetaCommand(MetaCommand::Exit)), ".about" => Some(TokenData::MetaCommand(MetaCommand::About)), + ".version" => Some(TokenData::MetaCommand(MetaCommand::Version)), _ => None, } }