use std::str::FromStr;
use structopt::StructOpt;
type ParseError = &'static str;
#[derive(Debug, StructOpt, Clone, Default)]
#[structopt(name = "GraphFS ", about = "GraphFS tool")]
pub struct Args {
#[structopt(short = "h", long = "host")]
pub host: Option<String>,
#[structopt(short = "p", long = "port")]
pub port: Option<u16>,
#[structopt(long = "auth_path")]
pub authorized_path: Option<String>,
#[structopt[short = "w", long = "worker"]]
pub worker: Option<usize>,
#[structopt(long = "remote")]
pub remote: Option<bool>,
#[structopt(long = "auth_option")]
pub auth_option: Option<AuthOption>,
#[structopt(long = "username", about = "The auth username")]
pub username: Option<String>,
#[structopt(long = "password", about = "The auth password")]
pub password: Option<String>,
#[structopt(long = "public_key")]
pub pub_key: Option<String>,
#[structopt(long = "private_key")]
pub private_key: Option<String>,
#[structopt(long = "passphrase")]
pub pass_phrase: Option<String>,
#[structopt(long = "remote_host")]
pub remote_host: Option<String>,
#[structopt(long = "remote_port")]
pub remote_port: Option<String>,
#[structopt(long = "cert_path")]
pub cert_path: Option<String>,
#[structopt(long = "key_path")]
pub key_path: Option<String>,
#[structopt(long = "use_auth")]
pub use_auth: Option<bool>,
#[structopt(long = "manage_users")]
pub manage_users: Option<UserConfig>,
#[structopt(long = "acc_name")]
pub account_name: Option<String>,
#[structopt(long = "acc_email")]
pub account_email: Option<String>,
#[structopt(long = "acc_password")]
pub account_password: Option<String>,
#[structopt(long = "acc_permission")]
pub account_permission: Option<String>,
#[structopt(long = "secret")]
pub jwt_secret: Option<String>,
#[structopt(long = "jwt_duration")]
pub jwt_duration: Option<i64>,
#[structopt(long = "storage")]
pub storage: Option<String>,
#[structopt(long = "db_path")]
pub db_path: Option<String>,
#[structopt(long = "allow_origin")]
pub cors_origin: Option<String>,
}
impl Args {
pub fn new() -> Self {
Args::from_args()
}
}
#[derive(Debug, Clone)]
pub enum UserConfig {
AddUser,
UpdateUserName,
DeleteUser,
UpdateUserPermission,
UpdateUserPassword,
}
#[derive(Debug, Clone)]
pub enum AuthOption {
Password,
Agent,
PubkeyFile,
}
impl FromStr for AuthOption {
type Err = ParseError;
fn from_str(types: &str) -> Result<Self, Self::Err> {
match types {
"user_password" => Ok(Self::Password),
"user_agent" => Ok(Self::Agent),
"user_pub_key" => Ok(Self::PubkeyFile),
_ => Err("Could not parse auth type"),
}
}
}
impl FromStr for UserConfig {
type Err = ParseError;
fn from_str(types: &str) -> Result<Self, Self::Err> {
match types {
"add_user" => Ok(Self::AddUser),
"update_username" => Ok(Self::UpdateUserName),
"delete_user" => Ok(Self::DeleteUser),
"update_user_password" => Ok(Self::UpdateUserPassword),
"update_user_permission" => Ok(Self::UpdateUserPermission),
_ => Err("could not parse user config"),
}
}
}