diff options
| author | Fuwn <[email protected]> | 2021-05-17 10:16:42 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-17 10:16:42 +0000 |
| commit | 1b482ab22031ab9a895b2567ba10a2e553752303 (patch) | |
| tree | db4874c46b25655ba7c94b0ab435fdb0d681af55 /src/cli.rs | |
| parent | refactor(global): whirl_config modulized (diff) | |
| download | whirl-1b482ab22031ab9a895b2567ba10a2e553752303.tar.xz whirl-1b482ab22031ab9a895b2567ba10a2e553752303.zip | |
refactor(global): even more modules becoming crates
I did multiple checks and **yes**, everything still works perfectly fine.
Diffstat (limited to 'src/cli.rs')
| -rw-r--r-- | src/cli.rs | 89 |
1 files changed, 0 insertions, 89 deletions
diff --git a/src/cli.rs b/src/cli.rs deleted file mode 100644 index 6565845..0000000 --- a/src/cli.rs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective -// SPDX-License-Identifier: GPL-3.0-only - -use structopt::clap::{App, AppSettings, Arg, ArgMatches, Shell, SubCommand}; -use whirl_config::Config; - -use crate::subs::run; - -pub struct Cli; -impl Cli { - pub fn setup() -> ArgMatches<'static> { - let matches = Self::cli().get_matches(); - - std::env::set_var("DATABASE_URL", "whirl.sqlite3"); - - matches - } - - pub async fn execute(matches: ArgMatches<'_>) -> Result<(), Box<dyn std::error::Error>> { - if Config::get().whirlsplash.log.test { - error!("error"); - warn!("warn"); - info!("info"); - debug!("debug"); - trace!("trace"); - } - - if matches.is_present("run") { - run().await; - } else if let Some(cmd) = matches.subcommand_matches("config") { - if cmd.is_present("show") { - println!("{:#?}", Config::get()); - } - } else if let Some(shell) = matches.subcommand_matches("completions") { - if shell.is_present("powershell") { - Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::PowerShell, "."); - } else if shell.is_present("bash") { - Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Bash, "."); - } else if shell.is_present("elvish") { - Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Elvish, "."); - } else if shell.is_present("zsh") { - Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Zsh, "."); - } else if shell.is_present("fish") { - Self::cli().gen_completions(env!("CARGO_PKG_NAME"), Shell::Fish, "."); - } - debug!("generated shell completions"); - } else if matches.is_present("clean") { - let cleanable_directories = vec!["./log/"]; - for dir in cleanable_directories { - println!("cleaning directory '{}'", dir); - if let Err(e) = std::fs::remove_dir_all(dir) { - bail!("error delete directory '{}': {}", dir, e); - } - } - } - - Ok(()) - } - - fn cli<'a, 'b>() -> App<'a, 'b> { - App::new(env!("CARGO_PKG_NAME")) - .about(env!("CARGO_PKG_DESCRIPTION")) - .version(env!("CARGO_PKG_VERSION")) - .author(env!("CARGO_PKG_AUTHORS")) - .settings(&[AppSettings::SubcommandRequiredElseHelp]) - .subcommands(vec![ - SubCommand::with_name("run").about("Start the WorldServer"), - SubCommand::with_name("config") - .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommands(vec![SubCommand::with_name("show")]), - SubCommand::with_name("completions") - .setting(AppSettings::SubcommandRequiredElseHelp) - .about("Generate shell completions") - .subcommands(vec![ - SubCommand::with_name("powershell"), - SubCommand::with_name("bash"), - SubCommand::with_name("elvish"), - SubCommand::with_name("zsh"), - SubCommand::with_name("fish"), - ]), - SubCommand::with_name("clean") - .about("Delete Whirl generated files/ directories which are NOT critical. E.g., logs/"), - ]) - .args(&[ - Arg::with_name("debug").short("d").long("debug"), - Arg::with_name("trace").short("t").long("trace"), - ]) - } -} |