feat(meta): add about meta-command
This commit is contained in:
parent
c863d71409
commit
2dead7de0a
6 changed files with 39 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ insert ::= "insert"
|
||||||
select ::= "select"
|
select ::= "select"
|
||||||
|
|
||||||
meta-command ::= "." "exit"
|
meta-command ::= "." "exit"
|
||||||
|
| "about"
|
||||||
|
|
||||||
int ::= sign? digit+
|
int ::= sign? digit+
|
||||||
sign ::= "+"
|
sign ::= "+"
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,7 @@ i will use rustyline, since it seems like the most feature-complete
|
||||||
* TODO .about meta-command
|
* TODO .about meta-command
|
||||||
* TODO .version meta-command
|
* TODO .version meta-command
|
||||||
* TODO .license meta-command
|
* TODO .license meta-command
|
||||||
|
* TODO .help meta-command
|
||||||
|
|
||||||
* TODO parse insert statements in the form
|
* TODO parse insert statements in the form
|
||||||
insert <id:int> <username:string> <email:string>
|
insert <id:int> <username:string> <email:string>
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,31 @@
|
||||||
use insta::assert_snapshot;
|
use insta::assert_snapshot;
|
||||||
|
|
||||||
pub fn startup_msg() -> String {
|
pub fn startup_msg() -> String {
|
||||||
let name = env!("CARGO_PKG_NAME");
|
|
||||||
let version = env!("CARGO_PKG_VERSION");
|
|
||||||
let authors = env!("CARGO_PKG_AUTHORS");
|
let authors = env!("CARGO_PKG_AUTHORS");
|
||||||
|
let about = about_msg();
|
||||||
|
let shorthelp = shorthelp_msg();
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{name} v{version} started.\n\
|
"{about}\n\n\
|
||||||
Copyright 2025 {authors}. All rights reserved."
|
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",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
|
use crate::branding;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum MetaCommand {
|
pub enum MetaCommand {
|
||||||
Exit,
|
Exit,
|
||||||
|
About,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for MetaCommand {
|
impl std::fmt::Display for MetaCommand {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
MetaCommand::Exit => write!(f, "exit"),
|
MetaCommand::Exit => write!(f, "exit"),
|
||||||
|
MetaCommand::About => write!(f, "about"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -19,6 +23,10 @@ impl MetaCommand {
|
||||||
pub fn execute(&self) -> MetaCommandExecuteResult {
|
pub fn execute(&self) -> MetaCommandExecuteResult {
|
||||||
match self {
|
match self {
|
||||||
MetaCommand::Exit => MetaCommandExecuteResult { should_exit: true },
|
MetaCommand::Exit => MetaCommandExecuteResult { should_exit: true },
|
||||||
|
MetaCommand::About => {
|
||||||
|
print!("{}", branding::about_msg());
|
||||||
|
MetaCommandExecuteResult { should_exit: false }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,10 @@
|
||||||
source: src/branding.rs
|
source: src/branding.rs
|
||||||
expression: startup_msg()
|
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.
|
Copyright 2025 Khaïs COLIN. All rights reserved.
|
||||||
|
|
||||||
|
Type .license for licensing information
|
||||||
|
Type .help for usage information
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,7 @@ impl Tokenizer {
|
||||||
fn recognize_metacommand(word: &str) -> Option<TokenData> {
|
fn recognize_metacommand(word: &str) -> Option<TokenData> {
|
||||||
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)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue