fix(ux): cleaned up CLI and fixed interruptability when in daemon mode
This commit is contained in:
parent
e1c90a0484
commit
eeed35e0b5
21
src/api.rs
21
src/api.rs
|
@ -111,16 +111,15 @@ pub async fn start_worker(
|
||||||
port: u16,
|
port: u16,
|
||||||
tx: mpsc::Sender<(Call, oneshot::Sender<Result<Response>>)>,
|
tx: mpsc::Sender<(Call, oneshot::Sender<Result<Response>>)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
tokio::task::spawn(
|
info!("HTTP server starting on port {} ...", port);
|
||||||
HttpServer::new(move || {
|
let _ = HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.service(authenticate)
|
.service(authenticate)
|
||||||
.service(register)
|
.service(register)
|
||||||
.app_data(web::Data::new(ApiState { tx: tx.clone() }))
|
.app_data(web::Data::new(ApiState { tx: tx.clone() }))
|
||||||
})
|
})
|
||||||
.bind(("127.0.0.1", port))?
|
.bind(("127.0.0.1", port))?
|
||||||
.run(),
|
.run()
|
||||||
);
|
.await;
|
||||||
info!("HTTP server started");
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -17,15 +17,15 @@ struct Args {
|
||||||
dir: Option<PathBuf>,
|
dir: Option<PathBuf>,
|
||||||
|
|
||||||
/// Start in daemon / server mode
|
/// Start in daemon / server mode
|
||||||
#[arg(short = 'D', long)]
|
#[arg(short = 'D', long, value_name = "PORT")]
|
||||||
daemon: bool,
|
daemon: Option<u16>,
|
||||||
|
|
||||||
/// List all accounts
|
/// List all accounts
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
list: bool,
|
list: bool,
|
||||||
|
|
||||||
/// Delete one or multiple account(s)
|
/// Delete one or multiple (comma seperated) accounts
|
||||||
#[arg(short, long, use_value_delimiter = true, value_delimiter = ',')]
|
#[arg(short, long = "delete", use_value_delimiter = true, value_delimiter = ',', value_name = "USER(S)")]
|
||||||
deletions: Option<Vec<String>>,
|
deletions: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ async fn main() -> Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
if args.deletions == None &&
|
if args.deletions == None &&
|
||||||
!args.daemon &&
|
args.daemon == None &&
|
||||||
!args.list {
|
!args.list {
|
||||||
return Err(anyhow::Error::msg("Nothing to do. run `baseauth --help` for a list of commands"));
|
return Err(anyhow::Error::msg("Nothing to do. run `baseauth --help` for a list of commands"));
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,8 @@ async fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.daemon {
|
if let Some(port) = args.daemon {
|
||||||
api::start_worker(8080, tx).await?;
|
api::start_worker(port, tx).await?;
|
||||||
loop {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue