feat(meta): add about meta-command

This commit is contained in:
Khaïs COLIN 2025-05-30 15:48:02 +02:00
parent c863d71409
commit 2dead7de0a
Signed by: logistic-bot
SSH key fingerprint: SHA256:3zI3/tx0ZpCLHCLPmEaGR4oeYCPMCzQxXhXutBmtOAU
6 changed files with 39 additions and 5 deletions

View file

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

View file

@ -229,6 +229,7 @@ i will use rustyline, since it seems like the most feature-complete
* TODO .about meta-command
* TODO .version meta-command
* TODO .license meta-command
* TODO .help meta-command
* TODO parse insert statements in the form
insert <id:int> <username:string> <email:string>

View file

@ -2,13 +2,31 @@
use insta::assert_snapshot;
pub fn startup_msg() -> String {
let name = env!("CARGO_PKG_NAME");
let version = env!("CARGO_PKG_VERSION");
let authors = env!("CARGO_PKG_AUTHORS");
let about = about_msg();
let shorthelp = shorthelp_msg();
format!(
"{name} v{version} started.\n\
Copyright 2025 {authors}. All rights reserved."
"{about}\n\n\
Copyright 2025 {authors}. All rights reserved.\n\n\
{shorthelp}"
)
}
pub fn about_msg() -> String {
let name = env!("CARGO_PKG_NAME");
let version = env!("CARGO_PKG_VERSION");
format!(
"{name} v{version} -- A database engine\n\
Note: This is experimental software. No maintenance is intendend."
)
}
pub fn shorthelp_msg() -> String {
String::from(
"Type .license for licensing information\n\
Type .help for usage information",
)
}

View file

@ -1,12 +1,16 @@
use crate::branding;
#[derive(Debug, Eq, PartialEq)]
pub enum MetaCommand {
Exit,
About,
}
impl std::fmt::Display for MetaCommand {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
MetaCommand::Exit => write!(f, "exit"),
MetaCommand::About => write!(f, "about"),
}
}
}
@ -19,6 +23,10 @@ impl MetaCommand {
pub fn execute(&self) -> MetaCommandExecuteResult {
match self {
MetaCommand::Exit => MetaCommandExecuteResult { should_exit: true },
MetaCommand::About => {
print!("{}", branding::about_msg());
MetaCommandExecuteResult { should_exit: false }
}
}
}
}

View file

@ -2,5 +2,10 @@
source: src/branding.rs
expression: startup_msg()
---
osdb v0.1.0 started.
osdb v0.1.0 -- A database engine
Note: This is experimental software. No maintenance is intendend.
Copyright 2025 Khaïs COLIN. All rights reserved.
Type .license for licensing information
Type .help for usage information

View file

@ -160,6 +160,7 @@ impl Tokenizer {
fn recognize_metacommand(word: &str) -> Option<TokenData> {
match word.to_lowercase().as_str() {
".exit" => Some(TokenData::MetaCommand(MetaCommand::Exit)),
".about" => Some(TokenData::MetaCommand(MetaCommand::About)),
_ => None,
}
}