Writing the writer.toml to a folder when running init.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
mod runner;
|
||||
|
||||
pub(crate) use runner::init_writer_folder;
|
||||
|
||||
25
src/command/init/runner.rs
Normal file
25
src/command/init/runner.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
use crate::cli::parameters::InitArgs;
|
||||
use crate::config::Config;
|
||||
|
||||
pub(crate) async fn init_writer_folder(args: &InitArgs) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let new_config = Config::default();
|
||||
if args.path.exists() && !args.path.is_dir() {
|
||||
return Err("The supplied path exists but is not a directory. Aborting.".into());
|
||||
}
|
||||
|
||||
if !args.path.exists() {
|
||||
std::fs::create_dir_all(&args.path)?;
|
||||
}
|
||||
|
||||
let existing_entries = std::fs::read_dir(&args.path)?;
|
||||
if existing_entries.count() != 0 {
|
||||
return Err("The directory is not empty. Aborting.".into());
|
||||
}
|
||||
|
||||
let mut config_file = File::create(args.path.join("writer.toml"))?;
|
||||
config_file.write_all(toml::to_string(&new_config)?.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user