use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
mod copier;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
name: Option<String>,
#[arg(short, long, value_name = "FILE")]
config: Option<PathBuf>,
#[arg(short, long, action = clap::ArgAction::Count)]
debug: u8,
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Test {
#[arg(short, long)]
list: bool,
},
CopyDocs {
#[arg(short, long)]
database: String,
#[arg(short, long)]
collection: String,
#[arg( long)]
id: Option<String>,
#[arg(long)]
filter_str: Option<String>,
#[arg(short, long)]
from: String,
#[arg(short, long)]
to: String,
#[arg(short, long)]
ignore_error: Option<bool>,
},
CreateUser {
name: String,
pwd: String,
roles: Vec<String>,
},
DropUser { name: String },
GrantUser { name: String, roles: Vec<String> },
RevokeUser { name: String, roles: Vec<String> },
UpdateUser {
name: String,
pwd: String,
roles: Vec<String>,
},
UsersInfo,
CreateRole,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
if let Some(name) = cli.name.as_deref() {
println!("Value for name: {}", name);
}
if let Some(config_path) = cli.config.as_deref() {
println!("Value for config: {}", config_path.display());
}
match cli.debug {
0 => println!("Debug mode is off"),
1 => println!("Debug mode is kind of on"),
2 => println!("Debug mode is on"),
_ => println!("Don't be crazy"),
}
match &cli.command {
Some(Commands::Test { list }) => {
if *list {
println!("Printing testing lists...");
} else {
println!("Not printing testing lists...");
}
Ok(())
}
Some(Commands::CopyDocs {
database,
collection,
id,
filter_str,
from,
to,
ignore_error,
}) => copier::copy_docs(copier::Param {
database: database.to_owned(),
collection: collection.to_owned(),
id: id.to_owned(),
filter_str: filter_str.to_owned(),
from: from.to_owned(),
to: to.to_owned(),
ignore_error: ignore_error.to_owned()
}).await,
Some(_) => {
Ok(())
},
None => {
Ok(())
}
}
}