3eeecb0010
an example.
69 lines
3.3 KiB
Rust
69 lines
3.3 KiB
Rust
use std::env;
|
|
use std::error::Error;
|
|
use std::fs::{File, create_dir_all};
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
use std::process::exit;
|
|
use tetanus::funcs::get_user_input;
|
|
|
|
pub fn install() -> Result<(), Box<dyn Error>> {
|
|
if let Some(homedir) = env::home_dir() {
|
|
let mut config_path = homedir.clone();
|
|
config_path.push(".config/tetanus");
|
|
let mut projects_path = config_path.clone();
|
|
projects_path.push("projects");
|
|
let mut module_path = config_path.clone();
|
|
module_path.push("modules/default");
|
|
create_dir_all(&module_path)?;
|
|
module_path.pop();
|
|
module_path.push("custom");
|
|
create_dir_all(&module_path)?;
|
|
module_path.pop();
|
|
let current_files_path = PathBuf::from(get_user_input(
|
|
"enter the path to store currently in progress project files (not notes), or none if you want to be propted everytime",
|
|
)?);
|
|
let current_notes_path = PathBuf::from(get_user_input(
|
|
"enter the path to store currently in progress project notes, or none if you want to be prompted everytime",
|
|
)?);
|
|
let upcoming_files_path = PathBuf::from(get_user_input(
|
|
"enter the path to store upcoming project files (not notes) or none if you want to be prompted everytime",
|
|
)?);
|
|
let upcoming_notes_path = PathBuf::from(get_user_input(
|
|
"enter the path to store upcoming project notes, or none if you want to be prompted everytime",
|
|
)?);
|
|
config_path.push("client.conf");
|
|
projects_path.push("default");
|
|
create_dir_all(&projects_path)?;
|
|
projects_path.push("project.conf");
|
|
let mut client_config_file = File::create(&config_path)?;
|
|
client_config_file.write(format!("projects: {}\n", projects_path.display()).as_bytes())?;
|
|
client_config_file.write("servers: 127.0.0.1:31337\n".as_bytes())?;
|
|
let mut default_project_file = File::create(projects_path)?;
|
|
config_path.pop();
|
|
config_path.push("server.conf");
|
|
let mut server_config_file = File::create(config_path)?;
|
|
server_config_file.write("address: 127.0.0.1:31337\n".as_bytes())?;
|
|
server_config_file.write("running: false\n".as_bytes())?;
|
|
default_project_file.write("org_name: default\n".as_bytes())?;
|
|
default_project_file.write("name: default\n".as_bytes())?;
|
|
default_project_file
|
|
.write(format!("notes: {}\n", current_files_path.display()).as_bytes())?;
|
|
default_project_file
|
|
.write(format!("files: {}\n", current_notes_path.display()).as_bytes())?;
|
|
default_project_file.write("stage: current".as_bytes())?;
|
|
client_config_file
|
|
.write(format!("current_files: {}\n", current_files_path.display()).as_bytes())?;
|
|
client_config_file
|
|
.write(format!("current_notes: {}\n", current_notes_path.display()).as_bytes())?;
|
|
client_config_file
|
|
.write(format!("upcoming_files: {}\n", upcoming_files_path.display()).as_bytes())?;
|
|
client_config_file
|
|
.write(format!("upcoming_notes: {}\n", upcoming_notes_path.display()).as_bytes())?;
|
|
client_config_file.write(format!("module_path: {}\n", module_path.display()).as_bytes())?;
|
|
} else {
|
|
eprintln!("error finding home directory!");
|
|
exit(1);
|
|
}
|
|
return Ok(());
|
|
}
|