Skip to content

Commit

Permalink
feat: add CLI for api server
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlin1228 committed Oct 5, 2024
1 parent f0e82b7 commit 8c8c46f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/api_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 11 additions & 4 deletions crates/api_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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("<the portable path>")?;
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();
Expand Down

0 comments on commit 8c8c46f

Please sign in to comment.