Skip to content

Commit

Permalink
Feat: Add args path for main
Browse files Browse the repository at this point in the history
  • Loading branch information
loloxwg committed Dec 23, 2023
1 parent f74f2ce commit 838c651
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ kip_db = "0.1.2-alpha.19"
rust_decimal = "1"
csv = "1"
regex = "1.10.2"
clap = "4.4.11"

[dev-dependencies]
cargo-tarpaulin = "0.27.1"
Expand Down
31 changes: 21 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::error::Error;
use std::io;

use clap::Parser;
use kip_sql::db::Database;
use kip_sql::types::tuple::create_table;
use std::error::Error;
use std::{env, io};

pub(crate) const BANNER: &str = "
██╗ ██╗██╗██████╗ ███████╗ ██████╗ ██╗
Expand All @@ -23,22 +23,33 @@ pub const BLOOM: &str = "
/ \\
_____________/_ __ \\_____________
";

/// KipSQL is a embedded database
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Path to db file
#[arg(short, long, default_value = "./data")]
path: String,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
println!("{} \nVersion: {}\n", BANNER, env!("CARGO_PKG_VERSION"));

println!(":) Welcome to the KipSQL, Please input sql.\n");
println!("Tips🔞: ");
println!("1. input \"quit\" to shutdown");
println!("2. all data is in the \'data\' folder in the directory where the application is run");

server_run().await?;

println!(
"2. all data is in the \'{}\' folder in the directory where the application is run",
args.path
);
server_run(args.path).await?;
Ok(())
}

async fn server_run() -> Result<(), Box<dyn Error>> {
let db = Database::with_kipdb("./data").await?;
async fn server_run(path: String) -> Result<(), Box<dyn Error>> {
let db = Database::with_kipdb(path).await?;

loop {
println!("> 👇👇🏻👇🏼👇🏽👇🏾👇🏿 <");
Expand Down

0 comments on commit 838c651

Please sign in to comment.