use std::{ ffi::OsStr, path::{Path, PathBuf}, }; use structopt::StructOpt; #[derive(Clone, Debug)] pub struct ConfigPath(pub PathBuf); impl Default for ConfigPath { fn default() -> ConfigPath { ConfigPath( dirs::config_dir() .unwrap_or(Path::new(".config").to_path_buf()) .join("gmarche"), ) } } impl From<&OsStr> for ConfigPath { fn from(v: &OsStr) -> ConfigPath { ConfigPath(PathBuf::from(v)) } } impl ToString for ConfigPath { fn to_string(&self) -> String { String::from( self.0 .as_path() .to_str() .expect("Error: Config dir is not UTF-8!"), ) } } #[derive(Clone, Debug, StructOpt)] #[structopt(name = "gmarche")] pub struct MainOpt { /// Directory #[structopt(short, long, parse(from_os_str), default_value)] pub dir: ConfigPath, /// Subcommand #[structopt(subcommand)] pub cmd: MainSubcommand, } #[derive(Clone, Debug, StructOpt)] pub enum MainSubcommand { /// Initialize config & db Init, /// Start server Start, }