feat(meta): version command

This commit is contained in:
Khaïs COLIN 2025-05-31 15:59:58 +02:00
parent 2dead7de0a
commit 315703d46b
Signed by: logistic-bot
SSH key fingerprint: SHA256:3zI3/tx0ZpCLHCLPmEaGR4oeYCPMCzQxXhXutBmtOAU
5 changed files with 21 additions and 7 deletions

View file

@ -10,6 +10,7 @@ select ::= "select"
meta-command ::= "." "exit" meta-command ::= "." "exit"
| "about" | "about"
| "version"
int ::= sign? digit+ int ::= sign? digit+
sign ::= "+" sign ::= "+"

View file

@ -226,8 +226,8 @@ i will use rustyline, since it seems like the most feature-complete
* DONE write a proper grammar * DONE write a proper grammar
* TODO .about meta-command * DONE .about meta-command
* TODO .version meta-command * DONE .version meta-command
* TODO .license meta-command * TODO .license meta-command
* TODO .help meta-command * TODO .help meta-command

View file

@ -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 name = env!("CARGO_PKG_NAME");
let version = env!("CARGO_PKG_VERSION"); let version = env!("CARGO_PKG_VERSION");
format!("{name} v{version}")
}
pub fn about_msg() -> String {
let version = version_msg();
format!( format!(
"{name} v{version} -- A database engine\n\ "{version} -- A database engine\n\
Note: This is experimental software. No maintenance is intendend." Note: This is experimental software. No maintenance is intendend."
) )
} }

View file

@ -4,6 +4,7 @@ use crate::branding;
pub enum MetaCommand { pub enum MetaCommand {
Exit, Exit,
About, About,
Version,
} }
impl std::fmt::Display for MetaCommand { impl std::fmt::Display for MetaCommand {
@ -11,6 +12,7 @@ impl std::fmt::Display for MetaCommand {
match self { match self {
MetaCommand::Exit => write!(f, "exit"), MetaCommand::Exit => write!(f, "exit"),
MetaCommand::About => write!(f, "about"), MetaCommand::About => write!(f, "about"),
MetaCommand::Version => write!(f, "version"),
} }
} }
} }
@ -27,6 +29,10 @@ impl MetaCommand {
print!("{}", branding::about_msg()); print!("{}", branding::about_msg());
MetaCommandExecuteResult { should_exit: false } MetaCommandExecuteResult { should_exit: false }
} }
MetaCommand::Version => {
print!("{}", branding::version_msg());
MetaCommandExecuteResult { should_exit: false }
},
} }
} }
} }

View file

@ -161,6 +161,7 @@ impl Tokenizer {
match word.to_lowercase().as_str() { match word.to_lowercase().as_str() {
".exit" => Some(TokenData::MetaCommand(MetaCommand::Exit)), ".exit" => Some(TokenData::MetaCommand(MetaCommand::Exit)),
".about" => Some(TokenData::MetaCommand(MetaCommand::About)), ".about" => Some(TokenData::MetaCommand(MetaCommand::About)),
".version" => Some(TokenData::MetaCommand(MetaCommand::Version)),
_ => None, _ => None,
} }
} }