added set dot env
parent
708ae57d1f
commit
1993aca4f2
|
@ -31,6 +31,12 @@ pub fn set_local_db(start: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_dot_env(start: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
toggle_after_line("#docker", 4, start)?;
|
||||||
|
toggle_after_line("#cidb", 2, !start)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn connections_env_comment(line: &str) -> bool {
|
fn connections_env_comment(line: &str) -> bool {
|
||||||
line.starts_with("ci.db.master.ip=") || line.starts_with("ci.db.master.port=")
|
line.starts_with("ci.db.master.ip=") || line.starts_with("ci.db.master.port=")
|
||||||
}
|
}
|
||||||
|
@ -39,52 +45,54 @@ fn should_commented_out(line: &str) -> bool {
|
||||||
line.starts_with("# ci.db.master.ip=") || line.starts_with("# ci.db.master.port=")
|
line.starts_with("# ci.db.master.ip=") || line.starts_with("# ci.db.master.port=")
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn comment_out_lines(input_path: &str, output_path: &str) -> io::Result<()> {
|
fn toggle_after_line(
|
||||||
// let file = File::open(input_path)?;
|
target_line_prefix: &str,
|
||||||
// let reader = BufReader::new(file);
|
num_lines: usize,
|
||||||
//
|
activate: bool,
|
||||||
// let modified_lines: Vec<String> = reader
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// .lines()
|
let file: File = File::open(LOCAL_CONNECTION_PATH)
|
||||||
// .map(|line| {
|
.with_context(|| format!("could not read file `{}`", LOCAL_CONNECTION_PATH))?;
|
||||||
// let line_content = line?;
|
let reader: BufReader<File> = BufReader::new(file);
|
||||||
// if should_comment_out(&line_content) {
|
|
||||||
// format!("# {}", line_content)
|
let mut modified_lines: Vec<String> = Vec::new();
|
||||||
// } else {
|
let mut relevant = false;
|
||||||
// line_content
|
let mut counter: usize = 0;
|
||||||
// }
|
|
||||||
// })
|
for line in reader.lines() {
|
||||||
// .collect();
|
let line_content = line?;
|
||||||
//
|
|
||||||
// // Write the modified content back to the output file
|
if counter == num_lines {
|
||||||
// let mut output_file = File::create(output_path)?;
|
relevant = false;
|
||||||
// for line in modified_lines {
|
}
|
||||||
// writeln!(output_file, "{}", line)?;
|
if line_content.trim_start().starts_with(target_line_prefix) {
|
||||||
// }
|
relevant = true;
|
||||||
//
|
modified_lines.push(line_content);
|
||||||
// Ok(())
|
continue;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// fn comment_in_lines(file_path: &str) -> io::Result<()> {
|
if relevant {
|
||||||
// let file = File::open(file_path)?;
|
modified_lines.push(toggle(&line_content, activate));
|
||||||
// let reader = BufReader::new(file);
|
counter += 1;
|
||||||
//
|
} else {
|
||||||
// let modified_lines: Vec<String> = reader
|
modified_lines.push(line_content);
|
||||||
// .lines()
|
}
|
||||||
// .map(|line| {
|
}
|
||||||
// let line_content = line?;
|
|
||||||
// if should_commented_out(&line_content) {
|
// Write the modified content back to the output file
|
||||||
// format!("{}", &line_content[2..]) // Uncomment by removing the leading "# "
|
fs::write(LOCAL_CONNECTION_PATH, modified_lines.join("\n")).expect("");
|
||||||
// } else {
|
|
||||||
// line_content
|
Ok(())
|
||||||
// }
|
}
|
||||||
// })
|
|
||||||
// .collect();
|
fn toggle(line: &str, activate: bool) -> String {
|
||||||
//
|
dbg!(line, activate);
|
||||||
// // Write the modified content back to the original file
|
if activate {
|
||||||
// let mut output_file = File::create(file_path)?;
|
return line.replacen('#', "", 1);
|
||||||
// for line in modified_lines {
|
}
|
||||||
// writeln!(output_file, "{}", line)?;
|
|
||||||
// }
|
if !line.starts_with('#') {
|
||||||
//
|
return format!("#{}", line);
|
||||||
// Ok(())
|
}
|
||||||
// }
|
|
||||||
|
line.to_string()
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use container::docker::start_docker_compose;
|
use container::docker::start_docker_compose;
|
||||||
use env::config::{load_config, DevToolsConf};
|
use env::config::{load_config, DevToolsConf};
|
||||||
|
|
||||||
use crate::{arguments::Arguments, config::parse::set_local_db};
|
use crate::{
|
||||||
|
arguments::Arguments,
|
||||||
|
config::parse::{set_dot_env, set_local_db},
|
||||||
|
};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
mod arguments;
|
mod arguments;
|
||||||
|
@ -17,6 +20,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
start_docker_compose(&config.container_service, &config.container_dir, start)?;
|
start_docker_compose(&config.container_service, &config.container_dir, start)?;
|
||||||
set_local_db(start)?;
|
set_local_db(start)?;
|
||||||
|
set_dot_env(start)?;
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Current directory: {}",
|
"Current directory: {}",
|
||||||
|
|
Loading…
Reference in New Issue