43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use anyhow::Result;
|
|
use clap::{Parser, Subcommand, Args};
|
|
|
|
use nom_nom_gc::models::{read_config, self, AppState, User, Configuration};
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(author, version, about, long_about = None)]
|
|
struct CLIArgs {
|
|
#[arg(short, long)]
|
|
config: Option<String>,
|
|
#[command(subcommand)]
|
|
command: Command
|
|
}
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
enum Command {
|
|
RegisterUser(RegisterUserArgs)
|
|
}
|
|
|
|
#[derive(Args, Debug)]
|
|
struct RegisterUserArgs {
|
|
username: String
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
let args = CLIArgs::parse();
|
|
let config = read_config(&args.config.unwrap_or("/etc/nom-nom-gc/config.json".to_owned()))
|
|
.unwrap_or_else(|e| panic!("Cannot read config file: {}", e.to_string()));
|
|
// todo: don't consume config in appstate new
|
|
let state = models::AppState::new(config.clone());
|
|
match args.command {
|
|
Command::RegisterUser(args) => register_user(args.username, state, config).await,
|
|
}
|
|
}
|
|
|
|
async fn register_user(user_name: String, state: AppState<'_>, conf: Configuration) -> Result<()> {
|
|
let user = User { user_name };
|
|
let uuid = state.generate_registration_link(user).await?;
|
|
println!("Registration link: {}/account/register/{}", &conf.url, &uuid.to_string());
|
|
Ok(())
|
|
}
|