diff options
| -rw-r--r-- | crates/whirl/src/cli.rs | 28 | ||||
| -rw-r--r-- | crates/whirl_config/src/lib.rs | 4 | ||||
| -rw-r--r-- | rustfmt.toml | 5 |
3 files changed, 33 insertions, 4 deletions
diff --git a/crates/whirl/src/cli.rs b/crates/whirl/src/cli.rs index c010e6a..d13b14b 100644 --- a/crates/whirl/src/cli.rs +++ b/crates/whirl/src/cli.rs @@ -1,7 +1,7 @@ // Copyright (C) 2021-2021 The Whirlsplash Collective // SPDX-License-Identifier: GPL-3.0-only -use std::str::FromStr; +use std::{io::Write, str::FromStr}; use structopt::clap::{App, AppSettings, Arg, SubCommand}; use whirl_config::Config; @@ -102,6 +102,23 @@ impl Cli { ("config", Some(s_matches)) => match s_matches.subcommand() { ("show", _) => println!("{:#?}", Config::get()), + ("generate", Some(s_s_matches)) => { + if std::path::Path::new(".whirl/Config.toml").exists() + && !s_s_matches.is_present("force") + { + info!( + "a configuration file is already present, if you would like to regenerate the \ + configuration file, execute this sub-command with the `--force` (`-f`) flag" + ); + } else { + let mut file = std::fs::File::create(".whirl/Config.toml") + .expect("unable to create configuration file"); + file + .write_all(include_bytes!("../../whirl_config/Config.default.toml")) + .expect("unable to write default configuration to generated configuration file"); + info!("successfully generated a new configuration file"); + } + } _ => unreachable!(), }, ("clean", _) => { @@ -132,7 +149,7 @@ impl Cli { SubCommand::with_name("run") .about("Start the WorldServer or a selection of sub-servers.") .long_about( - "Start the WorldServer by running this sub-command WITHOUT any arguments, start a \ + "Start the WorldServer by executing this sub-command WITHOUT any arguments, start a \ selection of sub-servers by passing a comma-separated list of sub-server types.", ) .arg( @@ -145,7 +162,12 @@ impl Cli { ), SubCommand::with_name("config") .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommands(vec![SubCommand::with_name("show")]), + .subcommands(vec![ + SubCommand::with_name("show"), + SubCommand::with_name("generate") + .alias("gen") + .arg(Arg::with_name("force").short("f").long("force")), + ]), SubCommand::with_name("clean").about( "Delete Whirl-generated files/ directories which are NOT critical. E.g., .whirl/logs/", ), diff --git a/crates/whirl_config/src/lib.rs b/crates/whirl_config/src/lib.rs index 81b71d7..218a249 100644 --- a/crates/whirl_config/src/lib.rs +++ b/crates/whirl_config/src/lib.rs @@ -79,6 +79,10 @@ impl Config { "unable to load configuration file, reverting to default value: {}", why ); + warn!( + "you should probably generate yourself a configuration file with `whirl config generate`!" + ); + Self::default() } else { Self::load().unwrap() diff --git a/rustfmt.toml b/rustfmt.toml index 0e9396b..777acfd 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,7 +2,7 @@ condense_wildcard_suffixes = true edition = "2018" enum_discrim_align_threshold = 20 error_on_line_overflow = true -error_on_unformatted = true +# error_on_unformatted = true fn_single_line = true force_multiline_blocks = true format_code_in_doc_comments = true @@ -28,3 +28,6 @@ use_field_init_shorthand = true use_try_shorthand = true where_single_line = true wrap_comments = true + +# crates/whirl/src/cli.rs:9:9 +error_on_unformatted = false |