taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

main.rs (2777B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2026 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 
     17 use std::sync::Arc;
     18 
     19 use clap::Parser as _;
     20 use taler_api::api::TalerRouter;
     21 use taler_apns_relay::{
     22     api::{RelayApi, router},
     23     config::ServeCfg,
     24     constants::CONFIG_SOURCE,
     25     db::{dbinit, pool},
     26     setup, worker,
     27 };
     28 use taler_build::long_version;
     29 use taler_common::{CommonArgs, cli::ConfigCmd, config::Config, taler_main};
     30 
     31 #[derive(clap::Parser, Debug)]
     32 #[command(long_version = long_version(), about, long_about = None)]
     33 struct Args {
     34     #[clap(flatten)]
     35     common: CommonArgs,
     36 
     37     #[command(subcommand)]
     38     cmd: Command,
     39 }
     40 
     41 #[derive(clap::Subcommand, Debug)]
     42 enum Command {
     43     /// Initialize taler-apns-relay database
     44     Dbinit {
     45         /// Reset database (DANGEROUS: All existing data is lost)
     46         #[clap(long, short)]
     47         reset: bool,
     48     },
     49     /// Check taler-apns-relay config
     50     Setup {
     51         /// Remove all registered devices
     52         #[clap(long, short)]
     53         reset: bool,
     54     },
     55     /// Run taler-apns-relay worker
     56     Worker {
     57         /// Execute once and return
     58         #[clap(long, short)]
     59         transient: bool,
     60     },
     61     /// Run taler-apns-relay HTTP server
     62     Serve,
     63     #[command(subcommand)]
     64     Config(ConfigCmd),
     65 }
     66 
     67 async fn run(cmd: Command, cfg: &Config) -> anyhow::Result<()> {
     68     match cmd {
     69         Command::Dbinit { reset } => {
     70             dbinit(cfg, reset).await?;
     71         }
     72         Command::Setup { reset } => {
     73             let pool = pool(cfg).await?;
     74             setup(cfg, &pool, reset).await?;
     75         }
     76         Command::Serve => {
     77             let pool = pool(cfg).await?;
     78             let cfg = ServeCfg::parse(cfg)?;
     79             let api = Arc::new(RelayApi::new(pool));
     80             router(api).serve(cfg.serve, None).await?;
     81         }
     82         Command::Worker { transient } => {
     83             let pool = pool(cfg).await?;
     84             worker::run(cfg, &pool, transient).await?;
     85         }
     86         Command::Config(cmd) => cmd.run(cfg)?,
     87     }
     88     Ok(())
     89 }
     90 
     91 fn main() {
     92     let args = Args::parse();
     93     taler_main(CONFIG_SOURCE, args.common, async |cfg| {
     94         run(args.cmd, &cfg).await
     95     });
     96 }