Line data Source code
1 : use bliki::user::add_user;
2 : use clap::{Arg, Command};
3 : use inquire::{Password, PasswordDisplayMode};
4 :
5 0 : fn add_user_cmd() -> Command {
6 0 : Command::new("bliki-add-user")
7 0 : .about("Add an admin user to bliki")
8 0 : .arg(
9 0 : Arg::new("dbpath")
10 0 : .short('d')
11 0 : .default_value("bliki.sqlite3")
12 0 : .help("Path to the SQLite database to use"),
13 : )
14 0 : .arg(Arg::new("username").short('u').required(true).help("The username of the user."))
15 0 : }
16 :
17 0 : fn main() -> anyhow::Result<()> {
18 0 : let cmd = add_user_cmd();
19 0 : let args = cmd.get_matches();
20 0 : let dbpath = args.get_one::<String>("dbpath").unwrap();
21 0 : let db = bliki::db::new(dbpath.into())?;
22 0 : let username = args.get_one::<String>("username").unwrap();
23 0 : let password = Password::new("Input a password:")
24 0 : .with_display_mode(PasswordDisplayMode::Masked)
25 0 : .prompt()?;
26 0 : add_user(&db, username.to_string(), password.as_bytes())?;
27 0 : Ok(())
28 0 : }
|