add cli
This commit is contained in:
parent
90b2d89a81
commit
c6e73e0303
2176
Cargo.lock
generated
2176
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -10,4 +10,5 @@ neo4rs = "0.7.1"
|
|||||||
tokio = "1.37.0"
|
tokio = "1.37.0"
|
||||||
rocket = "0.5.0"
|
rocket = "0.5.0"
|
||||||
rocket_okapi = { version = "0.8.0", features = ["swagger"] }
|
rocket_okapi = { version = "0.8.0", features = ["swagger"] }
|
||||||
anyhow = "1.0.76"
|
anyhow = "1.0.76"
|
||||||
|
clap = { version = "4.5.4", features = ["derive"] }
|
||||||
|
23
README.md
23
README.md
@ -12,10 +12,31 @@ To start the project run:
|
|||||||
|
|
||||||
`cargo run --package graphdbhue3 --bin graphdbhue3`
|
`cargo run --package graphdbhue3 --bin graphdbhue3`
|
||||||
|
|
||||||
|
You can use the CLI interface to select the proper db credentials:
|
||||||
|
```
|
||||||
|
❯ ./graphdbhue3 --help
|
||||||
|
Simple Route planning application
|
||||||
|
|
||||||
|
Usage: graphdbhue3 [OPTIONS]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--host <HOST> host of db [default: 127.0.0.1]
|
||||||
|
--port <PORT> port of db [default: 7687]
|
||||||
|
--username <USERNAME> username of db [default: ]
|
||||||
|
--password <PASSWORD> password of db [default: ]
|
||||||
|
-h, --help Print help
|
||||||
|
-V, --version Print version
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Appending cli parameters to the above `cargo run` command is as simple as:
|
||||||
|
|
||||||
|
`cargo run --package graphdbhue3 --bin graphdbhue3 -- --username <yourusername> --password <yourpwd>`
|
||||||
|
|
||||||
## Accessing Web Interface
|
## Accessing Web Interface
|
||||||
The API is exposed on Port `8081`.
|
The API is exposed on Port `8081`.
|
||||||
|
|
||||||
Access it through the Swagger Web UI: [http://localhost:8081](http://localhost:8081)
|
Access it through the Swagger Web UI: [http://localhost:8081/docs](http://localhost:8081/docs)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
29
src/main.rs
29
src/main.rs
@ -1,3 +1,4 @@
|
|||||||
|
use clap::Parser;
|
||||||
use crate::backend::backend::build_api;
|
use crate::backend::backend::build_api;
|
||||||
use neo4rs::Graph;
|
use neo4rs::Graph;
|
||||||
use rocket::Config;
|
use rocket::Config;
|
||||||
@ -6,15 +7,35 @@ use rocket_okapi::swagger_ui::{make_swagger_ui, SwaggerUIConfig};
|
|||||||
mod backend;
|
mod backend;
|
||||||
mod graph;
|
mod graph;
|
||||||
|
|
||||||
|
/// Simple Route planning application
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(version, about, long_about = None)]
|
||||||
|
struct Args {
|
||||||
|
/// host of db
|
||||||
|
#[arg(long, default_value_t=String::from("127.0.0.1"))]
|
||||||
|
host: String,
|
||||||
|
|
||||||
|
/// port of db
|
||||||
|
#[arg(long, default_value_t = 7687)]
|
||||||
|
port: u16,
|
||||||
|
|
||||||
|
/// username of db
|
||||||
|
#[arg(long, default_value_t = String::new())]
|
||||||
|
username: String,
|
||||||
|
|
||||||
|
/// password of db
|
||||||
|
#[arg(long, default_value_t = String::new())]
|
||||||
|
password: String,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let args = Args::parse();
|
||||||
let tokio = tokio::runtime::Runtime::new().expect("Failed to spawn tokio runtime");
|
let tokio = tokio::runtime::Runtime::new().expect("Failed to spawn tokio runtime");
|
||||||
|
|
||||||
tokio.block_on(async move {
|
tokio.block_on(async move {
|
||||||
let uri: String = "127.0.0.1:7687".to_string();
|
let uri: String = format!("{}:{}", args.host, args.port);
|
||||||
let user = "";
|
|
||||||
let pass = "";
|
|
||||||
// connect to neo4j database
|
// connect to neo4j database
|
||||||
let graph = Graph::new(uri, user, pass).await.unwrap();
|
let graph = Graph::new(uri, args.username, args.password).await.unwrap();
|
||||||
|
|
||||||
// configure api port and interface
|
// configure api port and interface
|
||||||
let config = Config {
|
let config = Config {
|
||||||
|
Loading…
Reference in New Issue
Block a user