You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
936 B
Rust

use std::fs;
use crate::cli::RemoteConfigRecord;
use crate::config::Config;
use std::fs::File;
use std::io::prelude::*;
#[derive(Debug)]
pub enum InitError {
Io(std::io::Error),
Serde(serde_json::error::Error)
}
fn create_dirsync_dirs() -> Result<(), std::io::Error> {
fs::create_dir_all("./.dirsync/actions/onSyncDidFinish")?;
Ok(())
}
pub fn init_dirsync_dir(remote_options: RemoteConfigRecord) -> Result<(), InitError> {
create_dirsync_dirs().map_err(|err| InitError::Io(err))?;
let _ignore_file = File::create("./.dirsync/ignore").map_err(|err| InitError::Io(err))?;
let mut config_file = File::create("./.dirsync/config.json").map_err(|err| InitError::Io(err))?;
let config = Config::new(remote_options);
let json = serde_json::to_string_pretty(&config).map_err(|err| InitError::Serde(err))?;
config_file.write_all(json.as_bytes()).map_err(|err| InitError::Io(err))?;
Ok(())
}