From 2dead7de0aec7ad236ceafd4c002ddd5fec75493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Fri, 30 May 2025 15:48:02 +0200 Subject: [PATCH] feat(meta): add about meta-command --- grammar.ebnf | 1 + notes.org | 1 + src/branding.rs | 26 ++++++++++++++++--- src/meta_commands.rs | 8 ++++++ .../osdb__branding__startup_msg.snap | 7 ++++- src/tokens.rs | 1 + 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/grammar.ebnf b/grammar.ebnf index 6fd2ecb..e979f99 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -9,6 +9,7 @@ insert ::= "insert" select ::= "select" meta-command ::= "." "exit" + | "about" int ::= sign? digit+ sign ::= "+" diff --git a/notes.org b/notes.org index 9d7ccc2..76423a1 100644 --- a/notes.org +++ b/notes.org @@ -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 diff --git a/src/branding.rs b/src/branding.rs index c580531..b4418d7 100644 --- a/src/branding.rs +++ b/src/branding.rs @@ -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", ) } diff --git a/src/meta_commands.rs b/src/meta_commands.rs index 59ff37f..d93a079 100644 --- a/src/meta_commands.rs +++ b/src/meta_commands.rs @@ -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 } + } } } } diff --git a/src/snapshots/osdb__branding__startup_msg.snap b/src/snapshots/osdb__branding__startup_msg.snap index 97e76fa..b66daa3 100644 --- a/src/snapshots/osdb__branding__startup_msg.snap +++ b/src/snapshots/osdb__branding__startup_msg.snap @@ -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 diff --git a/src/tokens.rs b/src/tokens.rs index b810d17..2c3464b 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -160,6 +160,7 @@ impl Tokenizer { fn recognize_metacommand(word: &str) -> Option { match word.to_lowercase().as_str() { ".exit" => Some(TokenData::MetaCommand(MetaCommand::Exit)), + ".about" => Some(TokenData::MetaCommand(MetaCommand::About)), _ => None, } }