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