diff --git a/Cargo.lock b/Cargo.lock index f4e1912..5288dc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,6 +372,7 @@ dependencies = [ "actix-cors", "actix-web", "anyhow", + "clap", "dt_core", "serde", ] diff --git a/crates/api_server/Cargo.toml b/crates/api_server/Cargo.toml index 6982f6c..d491b6d 100644 --- a/crates/api_server/Cargo.toml +++ b/crates/api_server/Cargo.toml @@ -9,6 +9,7 @@ version = "0.1.0" [dependencies] anyhow = { workspace = true } serde = { workspace = true } +clap = { workspace = true } actix-web = "4" actix-cors = "0.7" diff --git a/crates/api_server/src/main.rs b/crates/api_server/src/main.rs index a4ba979..8fcb456 100644 --- a/crates/api_server/src/main.rs +++ b/crates/api_server/src/main.rs @@ -1,5 +1,6 @@ use actix_cors::Cors; use actix_web::{error, get, web, App, HttpServer, Result}; +use clap::Parser; use dt_core::{ graph::used_by_graph::UsedByGraph, portable::Portable, @@ -140,12 +141,18 @@ async fn search( })) } +#[derive(Parser)] +#[command(version, about = "Start the server to provide search API", long_about = None)] +struct Cli { + /// Portable path + #[arg(short)] + portable: String, +} + #[actix_web::main] async fn main() -> std::io::Result<()> { - // TODO: get portable path from args - // let mut file = File::open("")?; - let mut file = - File::open("/Users/linweitang/rust/js-symbol-dependency-tracker/outputs/naopleon-06.json")?; + let cli = Cli::parse(); + let mut file = File::open(cli.portable)?; let mut exported = String::new(); file.read_to_string(&mut exported)?; let portable = Portable::import(&exported).unwrap();