Move argument parsing in separate module

This commit is contained in:
George Kaklamanos 2023-05-23 19:27:20 +03:00
parent 60af1c3d0b
commit 6653339da7
2 changed files with 19 additions and 15 deletions

17
src/cli.rs Normal file
View file

@ -0,0 +1,17 @@
use clap::Parser;
#[derive(Parser)]
#[command(version, about)]
pub struct Cli {
/// SpaceAPI endpoint
#[arg(short, long)]
pub url: String,
/// Period of querying, in seconds
#[arg(short, long, default_value_t = 300)]
pub delay: u64,
}
pub fn parse() -> Cli {
Cli::parse()
}

View file

@ -1,18 +1,5 @@
use clap::Parser;
mod client;
#[derive(Parser)]
#[command(version, about)]
struct Cli {
/// SpaceAPI endpoint
#[arg(short, long)]
url: String,
/// Period of querying, in seconds
#[arg(short, long, default_value_t = 300)]
delay: u64,
}
mod cli;
use std::sync::{Arc, Mutex};
type Body = Arc<Mutex<String>>;
@ -21,7 +8,7 @@ use rocket::{get, launch, routes, State};
#[launch]
fn rocket() -> _ {
let cli = Cli::parse();
let cli = cli::parse();
let body: Body = Arc::new(Mutex::new(String::new()));
let body_state = body.clone();